Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
0

How to make a script that animations stop when you click another one?

Asked by 4 years ago

I have a text button that shows the name of the emote in a frame with others and I have a script that makes you able to press on it then you player does the emote. This works but, when I make a looping animation there is no way to stop it. When you click it you do the animation and can't stop even when another is clicked. It looks really weird and people can't stop so I need a script that can make it stop when another emote is clicked or just a stop text button whichever works. Thank you.

The script I use in the text button:

wait(3) Player = game.Players.LocalPlayer.Character animation1 = Player.Humanoid:LoadAnimation(script.Animation1) CanEmote = true

script.Parent.MouseButton1Click:connect(function() local emote = math.random(1,1) if emote == 1 and CanEmote == true then animation1:Play() CanEmote=false wait(2) CanEmote=true end end)

Anything I can do or add?

1 answer

Log in to vote
0
Answered by
Infocus 144
4 years ago

Hi! There is this property of the Humanoid called GetPlayingAnimationTracks, which returns all animations that are playing into an table. You then use a for loop to go through each one then stop them.

local Player = game.Players.LocalPlayer.Character
CanEmote = true
animation1 = Player.Humanoid:LoadAnimation(script.Animation1)

script.Parent.MouseButton1Click:connect(function()
    local emote = math.random(1, 1)
    if (emote == 1) and (CanEmote == true) then
        CanEmote = false
        local playing = Player.Humanoid:GetPlayingAnimationTracks()
        for _, v in pairs (playing) do
            v:Stop()
        end
        animation1:Play()
        wait(2)
        CanEmote = true
    end
end)
0
Thanks but, do I put it n the same local script or a different one. The text button has a local script inside and animation1 in the local script. Should I add something? DJTwisted_2 0 — 4y
0
Replace the script with that Infocus 144 — 4y
Ad

Answer this question