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

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

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)

1 comment

0

try not to seperate function it will be confusing.

2 answers

✓ Accepted answer
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.

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

1 comment

0

also no need to use local animtrack = nil since you can just do local animtrack without "="

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