Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
COMMUNITY QUESTION

0 Works in studio but not in game. How to use a TextButton to Stop an Animation?

Someone assisted me in getting this far, but I wanted to know how to get the code working for studios, but not in game, what is stopping it from actually working?

Thanks in advance.

It is a LOCAL SCRIPT.

local player = game.Players.LocalPlayer

local character = player.Character

local humanoid = character.Humanoid

script.Parent.MouseButton1Click:Connect(function()

local anims = humanoid:GetPlayingAnimationTracks()

for i,v in pairs(anims) do

v:Stop()

end

end)

 

script.Parent.MouseButton1Click:Connect(function()

local anims = humanoid:GetPlayingAnimationTracks()

for i,v in pairs(anims) do

if v.Name == "Anim" then

v:Stop()

end

end

end)

2 comments

0

Try using WaitForChild to stop any loading error.

1 answer

Thanks guys, with a bit of research that you've sent, I got it.

local player = game.Players.LocalPlayer

local character = player.Character

local humanoid = character:WaitForChild("Humanoid")

script.Parent.MouseButton1Click:Connect(function()

local anims = humanoid:GetPlayingAnimationTracks()

for i,v in pairs(anims) do

v:Stop()

end

end)

 

script.Parent.MouseButton1Click:Connect(function()

local anims = humanoid:GetPlayingAnimationTracks()

for i,v in pairs(anims) do

if v.Name == "Anim" then

v:Stop()

end

end

end)

This discussion is preserved as it was. New answers, comments, and votes are closed.