So I am creating a simulator and most people know that when you are holding the tool or weapon and you click it plays and animation and gives strength. I am not focusing on the strength yet but I just need help on the animation. So the tool I am using is a wand and when you are holding it and you click, the animation will play. Everything is fine except for the animation. The animation won't play. The AnimationId is correct and and the animation is not nil. Everything but the "AnimationIsNil" is printing. I have moved some lines to other places and it still does not work. If any of you have a solution please tell me.
This is a local script
in the StarterPlayerScripts
local mouse = game.Players.LocalPlayer:GetMouse() local Character = game.Players.LocalPlayer.Character if not Character or not Character.Parent then Character = game.Players.LocalPlayer.CharacterAdded:Wait() end local Humanoid = Character:WaitForChild("Humanoid") local Animator = Humanoid:WaitForChild("Animator") local WandMovement = Instance.new("Animation") WandMovement.AnimationId = "rbxassetid://6602046971" local Tool = game.Players.LocalPlayer.Backpack:FindFirstChildWhichIsA("Tool") Tool.Equipped:Connect(function() print("ToolEquippedFUnction") mouse.Button1Down:Connect(function() print("IntoMouseButtonFunction") local WandMovementAnimationTrack = Animator:LoadAnimation(WandMovement) WandMovementAnimationTrack:Play() if WandMovementAnimationTrack == nil then print("animationtrackisnil") else print("AnimationIsNotNil") end end) end)
Thank you for reading!
It will only play the animation when you equip and click at the same frame since it only fires the mouse click function when Tool equipped event is fired. So do this instead:
debounce = false local Character = game.Players.LocalPlayer.Character if not Character or not Character.Parent then Character = game.Players.LocalPlayer.CharacterAdded:Wait() end local Humanoid = Character:WaitForChild("Humanoid") local Animator = Humanoid:WaitForChild("Animator") local WandMovement = Instance.new("Animation") WandMovement.AnimationId = "rbxassetid://6602046971" local Tool = game.Players.LocalPlayer.Backpack:FindFirstChildWhichIsA("Tool") Mouse.Button1Down:Connect(function() if debounce = false then debounce = true if Character:FindFirstChild(""..Tool.Name) then print("IntoMouseButtonFunction") local WandMovementAnimTrack = Animator:LoadAnimation(WandMovement) WandMovementAnimTrack:Play() if WandMovementAnimTrack == nil then print("animationtrackisnil") else print("AnimationIsNotNil") end end else return end end) Mouse.Button1Up:Connect(function() wait() debounce = false end)
I added debounce (cooldown) in case that was the problem.
Instead of
Animator:LoadAnimation(WandMovement)
you should try doing
Humanoid:LoadAnimation(WandMovement)
If this doesn't work, try changing the animation priority. I hope this helped!