#help
13 messages · Page 1 of 1 (latest)
-- Insert your animation ID here
local ANIMATION_ID = "rbxassetid://17191900926" -- Replace 123456789 with your animation ID
-- Function to play animation
local function playAnimation(character)
local humanoid = character:FindFirstChildOfClass("Humanoid")
if humanoid then
local animation = Instance.new("Animation")
animation.AnimationId = ANIMATION_ID
local animationTrack = humanoid:LoadAnimation(animation)
animationTrack:Play()
end
end
-- Function to handle tool equipped event
local function onToolEquipped(tool)
local character = tool.Parent
if character and character:IsA("Model") and character:IsDescendantOf(game.Players) then
playAnimation(character)
end
end
-- Connect the tool equipped event to the handler function
game.Players.PlayerAdded:Connect(function(player)
player.CharacterAdded:Connect(function(character)
character.ChildAdded:Connect(function(child)
if child:IsA("Tool") then
child.Equipped:Connect(function()
onToolEquipped(child)
end)
end
end)
end)
end)
Why doesn't this work?
Meant to look like this
Hello! here is the fixed script if this doesnt work please let me know!
-- Insert your animation ID here
local ANIMATION_ID = "rbxassetid://17191900926" -- Replace 123456789 with your animation ID
-- Function to play animation
local function playAnimation(character)
local humanoid = character:FindFirstChildOfClass("Humanoid")
if humanoid then
local animation = Instance.new("Animation")
animation.AnimationId = ANIMATION_ID
local animationTrack = humanoid:LoadAnimation(animation)
animationTrack:Play()
end
end
-- Function to handle tool equipped event
local function onToolEquipped(tool)
local character = tool.Parent
if character and character:IsA("Model") and character:IsDescendantOf(game.Players.LocalPlayer) then
playAnimation(character)
end
end
-- Connect the tool equipped event to the handler function
game.Players.PlayerAdded:Connect(function(player)
player.CharacterAdded:Connect(function(character)
character.ChildAdded:Connect(function(child)
if child:IsA("Tool") then
child.Equipped:Connect(function()
onToolEquipped(child)
end)
end
end)
end)
end)
Changes made:
- Replaced
game.Playerswithgame.Players.LocalPlayerinonToolEquippedfunction to ensure it only works for the local player's character. - Corrected the check for
character:IsDescendantOf(game.Players.LocalPlayer)to make sure it's the character of the local player.
With these changes, the script should now correctly play the animation when the local player equips a tool. Make sure to replace ANIMATION_ID with the actual ID of your animation.
@paper estuary
-- Insert your animation ID here
local 17191900926 = "rbxassetid://17191900926" -- Replace 123456789 with your animation ID
-- Function to play animation
local function playAnimation(character)
local humanoid = character:FindFirstChildOfClass("Humanoid")
if humanoid then
local animation = Instance.new("Animation")
animation.AnimationId = 17191900926
local animationTrack = humanoid:LoadAnimation(animation)
animationTrack:Play()
end
end
-- Function to handle tool equipped event
local function onToolEquipped(tool)
local character = tool.Parent
if character and character:IsA("Model") and character:IsDescendantOf(game.Players.LocalPlayer) then
playAnimation(character)
end
end
-- Connect the tool equipped event to the handler function
game.Players.PlayerAdded:Connect(function(player)
player.CharacterAdded:Connect(function(character)
character.ChildAdded:Connect(function(child)
if child:IsA("Tool") then
child.Equipped:Connect(function()
onToolEquipped(child)
end)
end
end)
end)
end)
@cerulean wave
** You are now Level 1! **