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

Need help with custom emotes not stopping after command? Help!

Asked by
djwchon 10
3 years ago

I have this script here, but when I type "/e stop," it won't work. I've been trying to do this for 30 minutes now. Help!

local animation = Instance.new("Animation")
animation.AnimationId = "rbxassetid://27789359"
local animtrack = nil

function onChatted(message, player)
    if message == ("/e classic") then
        local character = game.Workspace[player.Name]
        animtrack = character.Humanoid:LoadAnimation(animation)
        animtrack:Play()

        if message == ("/e stop")then
            local character = game.Workspace[player.Name]
            animtrack = character.Humanoid:LoadAnimation(animation)
            animtrack:Stop()
        end
    end
end

game.Players.PlayerAdded:Connect(function(player)
    player.Chatted:connect(function(message) onChatted(message, player) end)
end)
0
try not to seperate function it will be confusing. WINDOWS10XPRO 438 — 3y

2 answers

Log in to vote
0
Answered by 3 years ago
Edited 3 years ago
local animation = Instance.new("Animation")
animation.AnimationId = "rbxassetid://27789359"
local animtrack
local danced = false

game.Players.PlayerAdded:Connect(function(Player)
    Player.Chatted:Connect(function(Message)
        if Message == "/e classic" and not danced then
    local character = game.Workspace[player.Name]
                animtrack = character.Humanoid:LoadAnimation(animation)
                animtrack:Play()
                danced = true
        elseif Message == "/e stop" and danced then
            local character = game.Workspace[player.Name]
                animtrack = character.Humanoid:LoadAnimation(animation)
                animtrack:Stop()
                danced = false
        end
    end)
end)

function(message) onChatted(message, player) end) is truly useless since u already make a function called OnChatted

so just do player.Chatted:Connect(OnChatted)

and try not to use :connect with the lower c, it's deprecated.

Ad
Log in to vote
0
Answered by 3 years ago

Try this

local animation = Instance.new("Animation")
    animation.AnimationId = "rbxassetid://27789359"
    local animtrack = nil

function onChatted(message, player)
        local character = game.Workspace[player.Name]
       local animtrack = character.Humanoid:LoadAnimation(animation)
       if message == ("/e classic") then
            animtrack:Play()
      elseif message == ("/e stop")then
              animtrack:Stop()
      end
end

game.Players.PlayerAdded:Connect(function(player)
    player.Chatted:connect(function(message) onChatted(message, player) end)
end)

So what I did here was took the char and animtrack out of the if statement so everything within access the same animtrack. your problem was that you made two separate if statements and within each u set a new animtrack so then you were playing the first animtrack then the second time you were trying to stop the new animtrack. another problem is that since if message == ("/e stop") was within if message == ("/e classic") then that would mean if message was ever /e stop it'd have to be /e classic first and then /e stop, but message can't be two things at once so if it's already /e classic it'll never be /e stop at the same time making it so that you will never go into the /e stop section

using elseif checks the first if and if it's not true it'll move to the next and if it is true the script doesn't go on

0
also no need to use local animtrack = nil since you can just do local animtrack without "=" WINDOWS10XPRO 438 — 3y

Answer this question