I have an AI character that is supposed to walk toward you, and play an animation. It does this, but just spams the first few frames of said animation, and then stops.
anim = Instance.new("Animation",script.Parent.Parent.Humanoid) anim.AnimationId = "http://www.roblox.com/asset/?id=5063671356" humanoid = script.Parent.Parent.Humanoid function onTouched(hit) local human = hit.Parent:findFirstChild("Humanoid") if (human ~= nil) then local playAnim = humanoid:LoadAnimation(anim) playAnim:play() end end script.Parent.Touched:connect(onTouched)
any help?
EDIT: This script is located in the models upper torso if that is any help.
The most common problem with Touched functions is that they run more than once. Add a debounce variable that stops it from running more than once in a certain time.
anim = Instance.new("Animation",script.Parent.Parent.Humanoid) anim.AnimationId = "http://www.roblox.com/asset/?id=5063671356" humanoid = script.Parent.Parent.Humanoid local debounce = false function onTouched(hit) local human = hit.Parent:findFirstChild("Humanoid") if (human ~= nil) and debounce == false then debounce = true local playAnim = humanoid:LoadAnimation(anim) playAnim:play() playAnim.Stopped:Wait() -- you should change the delay, but this means that the next line doesn't run until the animation stops. debounce = false end end script.Parent.Touched:connect(onTouched)
Is the NPC doing anything else?