✓ Accepted answer
"Touch" is a touchy event, because it's possible to execute numerous functions in one touch. To reduce the function executions, implement a debounce, which executes the function one at a time.
Animation = Instance.new("Animation", script.Parent)
Animation.AnimationId = "http://www.roblox.com/asset/?id=94161088"
Debounce = false
function Anim()
if not Debounce then
Debounce = true
local AnimController = Instance.new("AnimationController", script.Parent)
local AnimTrack = AnimController:LoadAnimation(Animation)
AnimTrack:Play()
wait(2)
Debounce = false
end
end
script.Parent.Torso.Touched:connect(Anim)
It's quite odd that a new AnimationController object must be made every time the function runs, as it essentially replaces the Humanoid in the role of animations. So instead of creating a new one every time, just insert it manually in studio to the parent of this script.
AnimController = script.Parent.AnimationController
Animation = Instance.new("Animation", script.Parent)
Animation.AnimationId = "http://www.roblox.com/asset/?id=94161088"
AnimTrack = AnimController:LoadAnimation(Animation)
Debounce = false
function Anim()
if not Debounce then
Debounce = true
AnimTrack:Play()
wait(2)
Debounce = false
end
end
script.Parent.Torso.Touched:connect(Anim)
1 comment
Which script did you use?