Chat Command Not working?

Hey, im working on a chat comman script (localscript in StarterPlayerScripts)

Code:
local plr = game.Players.LocalPlayer
local charactersFolder = game.ReplicatedStorage.Characters

plr.Chatted:Connect(function(msg)
	local loweredText = string.lower(msg)
	if string.find(loweredText, "!spawn") then
		local SplitMessage = string.split(msg, " ")
		local Type = SplitMessage[2]
		print("Chatted, "..Type)
		if Type == "Normal" then
			local dummyClone = charactersFolder["Normal Dummy"]:Clone()
			dummyClone.Parent = workspace.Characters
			dummyClone:MoveTo(plr.Character.Torso.CFrame * CFrame.new(0,0,-3))
		elseif Type == "Weak" or "Weakest" then
			local dummyClone = charactersFolder["Weakest Dummy"]:Clone()
			dummyClone.Parent = workspace.Characters
			dummyClone:MoveTo(plr.Character.Torso.CFrame * CFrame.new(0,0,-3))
		elseif Type == "Strong" or "Strongest" then
			local dummyClone = charactersFolder["Strongest Dummy"]:Clone()
			dummyClone.Parent = workspace.Characters
			dummyClone:MoveTo(plr.Character.Torso.CFrame * CFrame.new(0,0,-3))
		elseif Type == "Inv" or "Invinsible" then
			local dummyClone = charactersFolder["Invincible Dummy"]:Clone()
			dummyClone.Parent = workspace.Characters
			dummyClone:MoveTo(plr.Character.Torso.CFrame * CFrame.new(0,0,-3))
		end
		print("Spawned "..Type.." Dummy")
	end
	if msg == "!clear" then
		workspace.Characters:ClearAllChildren()
	end
end)

The output is not printing anything, even with the !clear.

Thanks!

1 Like

Try doing a simple print(msg) as soon as the event should fire the function just to see what it says.

The only other note is, this should be working if you are using LegacyChat, but if you are using TextChatService, you’d need to use TextChatService.OnIncomingMessage, I believe that is the event.

3 Likes