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)
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)