First, you'll need to read a .Chatted event by using Player.Chatted
game.Players.PlayerAdded:Connect(function(player)
player.Chatted:Connect(function(msg)
end)
end)
Then, you'll need to use string.Sub to determine whether the player said "/a" at the begininng and to get the text after that.
game.Players.PlayerAdded:Connect(function(player)
player.Chatted:Connect(function(msg)
if string.sub(msg,1,3) == "/a " then
local announcementText = string.sub(msg,4)
end
end)
end)
Now, you can use Remote Events to talk to the client. For this, you'll need to put a RemoteEvent in ReplicatedStorage.
game.Players.PlayerAdded:Connect(function(player)
player.Chatted:Connect(function(msg)
if string.sub(msg,1,3) == "/a " then
local announcementText = string.sub(msg,4)
game.ReplicatedStorage["RemoteEventName"]:FireAllClients(announcementText)
end
end)
end)
Now, you'll need a LocalScript inside the Gui for when it recieves the call from the server.
game.ReplicatedStorage["RemoteEventName"].OnClientEvent:Connect(function(msg)
local textLabel = script.Parent.TextLabel
textLabel.Text = msg
end)
Or you can set the text into a StringValue and the TextLabel can always set its text to the value.
2 comments
Thank you! It works!
The third argument of string.sub() is exclusive, therefore the space will not be accounted for.