local tool = script.Parent local anim = tool:WaitForChild("animation") local player = game:GetService("Players").LocalPlayer local char = player.CharacterAdded:Wait() local humanoid = char:WaitForChild("Humanoid") local loadanim = humanoid:LoadAnimation(anim)
tool.Activated:Connect(function() loadanim:Play() end)
I already have the animation on the tool with the id
First of all, for future questions, can you format your script. that way its easier for people to answer
Second your problem is your waiting for CharacterAdded to run again, which if the player has the tool already, it will run right away, so changing local char = player.CharacterAdded:Wait()
to local char = player.Character
should be your fix.
Alongside this. Humanoid:LoadAnimation()
is no longer as in use, you should instead use Humanoid.Animator:LoadAnimation()
as its what is recommended.
wait() --// Services: local players = game:GetService("Players") --// Variables: local animation = script:WaitForChild(Animation Name) local tool = script.Parent --// Character: local player = players.LocalPlayer local character = player.Character local humanoid = character:WaitForChild("Humanoid") local animator = humanoid:WaitForChild("Animator") local loadedAnimation = animator:LoadAnimation(animation) --// Events: tool.Activated:Connect(function() loadedAnimation:Play() end)
This should help
Oh nvm i found the answer. The answer was the priority
wait() local players = game:GetService("Players") local animation = script:WaitForChild("Animation") local tool = script.Parent local player = players.LocalPlayer local character = player.Character local humanoid = character:WaitForChild("Humanoid") local animator = humanoid:WaitForChild("Animator") local loadedAnimation = animator:LoadAnimation(animation) loadedAnimation.Priority = Enum.AnimationPriority.Action tool.Activated:Connect(function() loadedAnimation:Play() end)
I added the priority and it works. Thank u both.