Hi and thanks for reading my question, I've been wondering for days on how to make a looping animation that never stops, when I try to do this, It cancels when it fires another animation, and I don't know how to stop it, basically I'm starting off a function where it fires if you have been dealt a certain amount of damage(haven't added that in yet) but what I have so far is clicking on a button, however, when you click on that button the animation plays, but jumping or stop walking just cancels the animation, here's what I have so far.
local a = Instance.new('Animation') a.AnimationId = 'rbxassetid://1171537883' local player = game.Players.LocalPlayer workspace:WaitForChild(player.Name,3) local trackanimation = nil local playstance = true function playAnimation(AnimationSource) if playstance == true then trackanimation = workspace[player.Name].Humanoid:LoadAnimation(a) while wait() do trackanimation:Play() end end end script.Parent.MouseButton1Click:connect(playAnimation)
help is extremely appreciated! Thanks.
Try to use pcall, it should help
Here’s what the code should look like
local a = Instance.new('Animation') a.AnimationId = 'rbxassetid://1171537883' local player = game.Players.LocalPlayer workspace:WaitForChild(player.Name,3) local trackanimation = nil local playstance = true function playAnim(source) pcall(function() if playstance == true then trackanimation = workspace[player.Name].Humanoid:LoadAnimation(a) while wait() do trackanimation:Play() end end end end
If that doesn’t work try storing the animation code in a empty script that has no other code in it.