I'm trying to make an animation onTouch event, but I don't want to let the player move, so I made a command that changes the player walkspeed, but it is worst than before. The animation doesn't play properly, any help?
local Anim = script.Parent.Animation -- Animation local debounce = false script.Parent.Touched:connect(function(hit) if hit.Parent:FindFirstChild("Humanoid") and debounce == false then debounce = true hit.Parent:findFirstChild("Humanoid").WalkSpeed = 0 local AnimTrack = hit.Parent.Humanoid:LoadAnimation(Anim) AnimTrack:Play() wait(2.8) -- Seconds Before You Can Play Animation Again. debounce = false hit.Parent:findFirstChild("Humanoid").WalkSpeed = 16 end end)
I'm confused on what you mean when you say the animation doesn't play properly, so I'm assuming it doesn't play at all. It may be that FindFirstChild is not capitalized on lines 7 and 12? I've just tested the following modified code and it seemed to work fine for me:
local anim = script.Parent.Animation local db = false script.Parent.Touched:connect(function(hit) local humanoid = hit.Parent:FindFirstChild("Humanoid") if humanoid and db == false then db = true humanoid.WalkSpeed = 0 local animTrack = humanoid:LoadAnimation(anim) animTrack:Play() wait(animTrack.Length) humanoid.WalkSpeed = 16 db = false end end)
However, if it still doesn't work, try making sure that your script and animation are inside the part or if the animation Id is correct.
Hope this helps