How to make when player chatted all players sees a Gui

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 :slight_smile:

17 Likes

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

9 Likes

@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)

Local script:

local remoteevent = "event" -- your remote event

	remoteevent.OnServerEvent:Connect(function(msg)
	script.Parent.Text = msg
	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)

image
image
And it says these errors.

6 Likes

The remote event is not a string. It’s a instance. Place a remote event (instance) inside the ReplicatedStorage, get the instance and fire it.
image
image

7 Likes

@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)

image

6 Likes

Explain what, the script or how the remote event works? because i already sent a document about the remoteevent

6 Likes

I just don’t know what to do :sob::sob:

6 Likes

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

8 Likes

That what I understood from the topic


The error is

After I fixed the error

6 Likes

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)

this should work

6 Likes

@Nick_chill
LOL! I DID REPLICATEDFIRST NOT STORAGE :laughing:
image
After I put it in storage this error happened

5 Likes

Oh my bad, change OnServerEvent to OnClientEvent

local remoteevent = game.ReplicatedStorage.RemoteEvent -- remote event

remoteevent.OnClientEvent: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)

I accidentally used the function OnServerEvent meaning the client fired the remote event instead of the server firing it

6 Likes

Yay! Finally it worked :smiley:
Thank you so much for help

7 Likes

No problem! If you want the text to be filtered. You can check out this document/article Text Filtering | Documentation - Roblox Creator Hub

6 Likes

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.