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

How to stop command emote animation the second time?

Asked by 3 years ago

I made a script with emotes. For example if you type /hands then an animation plays. What I want is that if the character says /hands again then the animation stops. Please help :)

Code:

local players = game:GetService("Players")

local command1 = "/hands"

function onChatted(chat, recipent, speaker)
    local name = speaker.Name
    chat = string.lower(chat)

    if (chat == command1) then
        local player = players:FindFirstChild(name)
        local Humanoid = player.Character.Humanoid


        local ActiveTracks = Humanoid:GetPlayingAnimationTracks()
        for _,v in pairs(ActiveTracks) do
            v:Stop()
        end
end

function onPlayerEntered(player)
    player.Chatted:Connect(function(chat,recipent) onChatted(chat,recipent,player) end)
end

game.Players.PlayerAdded:Connect(onPlayerEntered)

Thank you for taking your time!

1 answer

Log in to vote
0
Answered by 3 years ago

Use If Functions Example:

local On = false
if not On then
    print("On Is False")
    On = true
else
    print("On Is True")
    On = false
end
Ad

Answer this question