Chatted event didn't fire when using players.localplayer after I joined this server

It cannot be fired to run a function. Somewhat similar when playeradded event didn’t fire after a player joined the server.

local PLR = game.Players.LocalPlayer
PLR.Chatted:Connect(function(MSG)
	print("Prints message: "..MSG)
end)

I need a help on how do I fix this. I tried putting it to replicated first and starter player script.

1 Like

the chatted event does not work in local scripts

2 Likes

So should I put it in playeradded event and then chatted event inside?

1 Like

yep

(character limit)

1 Like

I did not work. I tried PlayerAdded:Wait() to return a local player, I tried PLR.Chatted:Wait() and I didn’t print the string that I type. And even this

local function WasChatted(MSG)
	print("Prints message: "..MSG)
end
repeat
	task.wait()
until PLAYERS.LocalPlayer
PLAYERS.LocalPlayer.Chatted:Connect(WasChatted)

It only works on server script.

1 Like

you cant use game.Players.LocalPlayer in a server script. A server script is designed to run on the “server,” which controls everything players see and do in the game. Think of the server as the brain that keeps track of everything happening in the game, such as player data, enemies, and important events.

A local script, on the other hand, runs on each player’s device individually. It’s like the player’s “personal assistant,” handling things specific to just them. This is why you can use game.Players.LocalPlayer, you’re just getting the player that this script works for

Here’s some code that will work for the server script:

game.Players.PlayerAdded:Connect(function(plr) -- when a player joins, we get that player. now we can do stuff with this player from the server script
	plr.Chatted:Connect(function(message) -- this detects if that player who joined sends a message. I also added the message variable incase you need it, that message variable is just the message that player sent.
		print(plr.Name.." says "..message)
		-- this is where your code can go
	end)
end)

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.