I tried to use “Chatted” or “PlayerAdded” with “Chatted” on local script but didn’t activate when I chat.
Here is the code
-- This local script is on StarterPlayerScripts
local PLR = game:GetService("Players").LocalPlayer
PLR.Chatted:Connect(function(MSG, Recipent)
print("Chatted", MSG, Recipent)
end
-- Or this
game.Players.PlayerAdded:Connect(function(PLR)
PLR.Chatted:Connect(function(MSG, Recipent)
print("Chatted", MSG, Recipent)
end)
end)
local Players = game:GetService("Players")
local Player = Players.LocalPlayer
local TextChatService = game:GetService("TextChatService")
local TextChannel = TextChatService:WaitForChild("RBXGeneral")
TextChannel.MessageReceived:Connect(function(message)
local text = message.Text
local source = message.TextSource
if source.UserId == Player.UserId then
print("Chatted", text)
end
end)
btw the recipient parameter is deprecated and doesn’t give anything
also i don’t think Player.Chatted works in the client, but someone correct me if I’m wrong
Its still not work because of inf yield using :WaitForChild(). Even I set task.wait(3) before :WaitForChild(), its still not working.
(Btw, This script is on local/client)
i see. in that case, i recommend using Remote Events in which the server can trigger events in the client and vice versa
you create two scripts, one in ServerScriptService, and one in StarterPlayerScripts like what you mentioned earlier, then create a RemoteEvent in ReplicatedStorage and name it whatever you like
server script:
local Players = game:GetService("Players")
local ReplicatedStorage = game:GetService("ReplicatedStorage")
local RemoteEvent = ReplicatedStorage.INSERT_REMOTE_EVENT_NAME_HERE
Players.PlayerAdded:Connect(function(Player)
Player.Chatted:Connect(function(message)
RemoteEvent:FireClient(Player, message)
end)
end)
client script:
local ReplicatedStorage = game:GetService("ReplicatedStorage")
local RemoteEvent = ReplicatedStorage:WaitForChild("INSERT_REMOTE_EVENT_NAME_HERE")
RemoteEvent.OnClientEvent:Connect(function(message)
print("Chatted", message)
end)