I’ve been trying to split a message which was sent by the script’s local player into args, but the function Chatted doesn’t even fire.
My script:
local Players = game:GetService("Players")
local Player = Players.LocalPlayer
function Chatted(Msg)
local Args = string.split(Msg," ")
print(Args)
end
Player.Chatted:Connect(Chatted)
NOTE: I tried adding print() before defining the function, it worked (which means the script is active). But somehow, the function still does not fire.
Are you using a Local script?For chatted events to work properly, you need to use server scripts. Not on the client.
Heres an example of the code.
local Players = game:GetService("Players")
function Chatted(Message)
local Args = string.split(Message, " ")
print(Args)
end
Players.PlayerAdded:Connect(function(Player)
Player.Chatted:Connect(Chatted)
end)
NOTE: make sure the server script is parented to ServerScriptService.