Player.Chatted working in studio but not in-game?

I haven’t experienced this issue before, and for some reason it just popped up after I’ve been working in studio for a bit.

All of my commands that use the Player.Chatted() event that have an if statement to see if the message is the actual command have broken. I have tried debugging the issue by putting print statements after that event, but nothing is appearing in output from those print statements.

This was just some code that I used to debug it. I’m pretty sure I’m just making some simple mistake that I overlooked, but if someone could help me fix this it would be appreciated.

game.Players.PlayerAdded:Connect(function(plr)
	plr.Chatted:Connect(function(msg)
		if msg == "hi" then
		print("test")
		end
	end)
end)

Is that the whole code you’re working with? This code should be working so I’m pinning it down to outside interference as to why this isn’t functioning the way you want it to. For example, you might have a yielding call before this which prevents the function from listening to PlayerAdded in time.

To avoid these kinds of scenarios for good, I’ve opted myself to create my functions separately and do all the connections at the end where necessary. For PlayerAdded, I connect it first then run it for all players that may be existing in the server before the function has a chance to get called on them.

local Players = game:GetService("Players")

local function playerAdded(player)
    player.Chatted:Connect(function (msg)
        print(msg)
    end)
end

Players.PlayerAdded:Connect(playerAdded)
for _, player in ipairs(Players:GetPlayers()) do
    playerAdded(player)
end
1 Like