How do I make an animation only play once after touching an object?
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.
01 | function onTouched(hit) |
02 | local human = hit.Parent:findFirstChild( "Humanoid" ) |
05 | local anim = human:LoadAnimation(script.Parent.Animation) |
13 | script.Parent.Touched:connect(onTouched) |
Thanks.