-
What do you want to achieve?
I want to get the message the player said in the chat. -
What is the issue?
I don’t know how to use the Player.Chatted. -
What solutions have you tried so far?
I searched for a while and found:
Player.Chatted
But I don’t know how to use it to get the message the player said in the chat…
Player.Chatted:Connect(function(msg)
print(msg) -- the msg parameter is the message send by the player
end)
Should be simple to learn.
If you’re using Player.Chatted
, you could check what he said, as @yyumchi gave you a short example of it, basically, that’s how the common ‘headless’ and ‘korblox’ commands work.
It doesn’t work, I put this in Starter Character Script is that the cause?
The usual way to use this script is by adding a script[server] and connecting to the player joined and then connect to the player messaging.
Sorry but I don’t understand what you said, I need to put this in a script in the ServeurScriptService ?
First things first, do you want to connect from a client script or a server script?
I just want to know what the player wrote in the chat
So I don’t know which way to go…
The best way to go is by the Player, so easily all you need to do is:
- Locate the player
game:GetService("Players").PlayerAdded:Connect(Player) end)
- Connect to chat from the player
Player.Chatted:Connect(function(msg) end)
A full code sample just for you😉, do put it in a serverscriptservice
local plr = game:GetService("Players")
plr.PlayerAdded:Connect(function(Player)
Player.Chatted:Connect(function(msg)
print(msg) -- the player's message
end)
end)
On the Studio Explorer on the left look for something Called ServerScriptService.
Then place a Server Script inside of it. Open it and paste this inside
game.Players.PlayerAdded:Connect(function(player)
player.Chatted:Connect(function(msg)
-- Cloud_Emmie's code snippet
print(msg) -- the msg parameter is the message send by the player
end)
end
This is how you do it
game.Players.PlayerAdded:Connect(function(plr)
plr.Chatted:Connect(function(message)
print(message) -- prints message
end)
end)
Thanks so much !!!
This helped me a lot !
Have a good day !
I have one last small question, I need the message variable in a local script located in StarterCharacterScripts and I don’t know how I can transfer it…
Insert a Remote Event in Replicate Storage name it msg then change your code in sss:
local msgR = game.ReplicatedStorage.msg
local plr = game:GetService("Players")
plr.PlayerAdded:Connect(function(Player)
Player.Chatted:Connect(function(msg)
msgR:FireClient(Player,msg) -- the player's message fired to client
end)
end)
Client side this script:
game.ReplicatedStorage.msg.OnClientEvent:connect(function(msg)
print(msg)
end)
Sorry but i don’t really understand…
I want to get the message the player said in a local script in StarterCharacterScript
If that’s not possible, can I get the message the player said in a local script located in StarterCharacterScripts?
Well I showed you getting the message on client via RemoteEvents
I need to create a remote event named “msg” and in my local script put this :
game.ReplicatedStorage.msg.OnClientEvent:connect(function(msg)
print(msg)
end)
?
You got it!
[Char Limit 30,Char]
So that’s what I have do and it doesn’t work …