I am making an obby sort of game and I have a lava jump like obstacle, and I have a script so that if you touch the object, a death animation plays. The issue is that sometimes the animation doesn't play, and sometimes, it plays the 1st few frames then repeats them. I think this is because I have it set the player's walkspeed to 0, and so the game thinks that the character is hitting the object over and over, therefore playing the animation over and over. I thought maybe I could make it so the player moves or gets pushed to another place, but, 1, their walkspeed is 0, and 2, I don't know how to do it. If anyone could help me then it would be very much appreciated! My code is below.
function onTouched(hit) local human = hit.Parent:findFirstChild("Humanoid") if human then human.WalkSpeed = 0 local anim = human:LoadAnimation(script.Parent.Animation) anim:Play() wait(2) human.Health = 1 wait(0.5) human.Health = 0 end end script.Parent.Touched:connect(onTouched)
Thanks.
BlackOrange3343 told me to set a debounce and I looked up a roblox dev page on it and I tried something and it fixed it! Here is the code.
local anim = false script.Parent.Touched:connect(function(hit) if not anim then anim = true if hit.Parent then human = hit.Parent:FindFirstChild("Humanoid") local anim = human:LoadAnimation(script.Parent.Animation) anim:Play() end wait(10) anim = false end end)
Thank you BlackOrange3343.