I get a error when i run this please help me
local player = game:GetService("Players").LocalPlayer local character = player.Character local animation = script.Parent:FindFirstChild("Animation") local swingAnimation local canSwing = true local debounce = 1 swingAnimation = character.Humanoid:LoadAnimation(animation) script.Parent.Activated:Connect(function() if canSwing then canSwing = false swingAnimation:Play() wait(debounce) canSwing = true end end)
Bro, Humanoid:LoadAnimation
is deprecated. It shouldn't be put to work anymore. Instead, use Animator:LoadAnimation
. I refactored your code a little bit. Just copy my script below, it should work just fine. But now, even more optimized. I hope this helps!
local player = game:GetService("Players").LocalPlayer local character = player.Character local humanoid = character:WaitForChild("Humanoid") local animator = humanoid:WaitForChild("Animator") --this!! local swingAnimation = animator:LoadAnimation(animation) local animation = script.Parent:FindFirstChild("Animation") local canSwing = true local debounce = 1 script.Parent.Activated:Connect(function() if canSwing then canSwing = false swingAnimation:Play() wait(debounce) canSwing = true end end)