Hello Developers, I tried to make a script that when the player message “/cs (word)” in the chat all the players sees a Gui text shows on their screen says the word, like for example if I chatted “/cs hi” all the players sees a Gui message box says hi like this
so I tried to make the script but I only made the chatted part because I have no idea to make the other part (public Gui not client Gui)
game.Players.PlayerAdded:Connect(function(plr)
plr.Chatted:Connect(function(msg)
if plr.Name == "i6Hx" then
local prefix = "/cs "
if (msg:find(prefix, 1, true) == 1) then
local x = string.sub(msg,(string.len(prefix)+1),-1)
print(x) -- I don't know what to do here 🙃
end
end
end)
end)
if anyone know how to make it you can tell me how and tell me the script, Thank you for your time
You can use a remoteevent to communicate from the server to all the clients from the server. You can fire the remote event to all clients with the message text. Once all the client gets the fired event, you can make the gui visible and the text to the specific message you sent.
Server Script:
local remoteevent = -- your remote event
game.Players.PlayerAdded:Connect(function(plr)
plr.Chatted:Connect(function(msg)
if plr.Name == "i6Hx" then
local prefix = "/cs "
if (msg:find(prefix, 1, true) == 1) then
local x = string.sub(msg,(string.len(prefix)+1),-1)
remoteevent:FireAllClients(x)
end
end
end)
end)
local script:
local remoteevent = -- your remote event
remoteevent.OnClientEvent:Connect(function(msg)
-- code (make the textlabel or something visible and change the textlabel's text to the msg)
end)
Although you didn’t really specify what you wanted. If you wanted ALL the players in the game to see the message, you can use MessagingService
@Nick_chill
It doesn’t work for some reason I made a local script inside of the gui and i set the local remoteevent to “event”
Public script:
local remoteevent = "event"
game.Players.PlayerAdded:Connect(function(plr)
plr.Chatted:Connect(function(msg)
if plr.Name == "i6Hx" then
local prefix = "/cs "
if (msg:find(prefix, 1, true) == 1) then
local x = string.sub(msg,(string.len(prefix)+1),-1)
remoteevent:FireAllClients(x)
end
end
end)
end)
@Nick_chill
Can you explain to me please, I don’t understand but I did this to try.
local remoteevent = game.ReplicatedStorage.RemoteEvent
game.Players.PlayerAdded:Connect(function(plr)
plr.Chatted:Connect(function(msg)
if plr.Name == "i6Hx" then
local prefix = "/cs "
if (msg:find(prefix, 1, true) == 1) then
local x = string.sub(msg,(string.len(prefix)+1),-1)
remoteevent:FireAllClients(x)
end
end
end)
end)
Remote events communicate information from the client to the server.
So you would use a remote event if you want all players in a server to see something that only you see
put the remote event inside ReplicatedStorage. You should read the document i sent
Server script (your congrats system command script)
local remoteevent = game.ReplicatedStorage.RemoteEvent -- gets the remote event
game.Players.PlayerAdded:Connect(function(plr)
plr.Chatted:Connect(function(msg)
if plr.Name == "i6Hx" then
local prefix = "/cs "
if (msg:find(prefix, 1, true) == 1) then
local x = string.sub(msg,(string.len(prefix)+1),-1)
remoteevent:FireAllClients(x) -- fires all clients with the argument (x)
end
end
end)
end)
local script
local remoteevent = game.ReplicatedStorage.RemoteEvent -- remote event
remoteevent.OnServerEvent:Connect(function(msg) -- gets the argument of the x (msg)
script.Parent.Text = msg -- changes text to the msg gotten from the remote event
script.Parent.Parent.TextLabel2.Transparency = 0
script.Parent.Parent.TextLabel2.TextTransparency = 0
script.Parent.Parent.TextLabel2.UIStrokeB.Transparency = 0
script.Parent.Parent.TextLabel2.UIStrokeC.Transparency = 0
wait(2)
script.Parent.Parent.TextLabel2.Transparency = 1
script.Parent.Parent.TextLabel2.TextTransparency = 1
script.Parent.Parent.TextLabel2.UIStrokeB.Transparency = 1
script.Parent.Parent.TextLabel2.UIStrokeC.Transparency = 1
end)