How do I make this text update for everyone in the server?

So, I’m trying to achieve to make it when I click the button It updates this SurfaceGui TextLabel from this StarterGui GUI TextButton.

local EC = script.Parent.EC
local PR = script.Parent.PR
local INV = script.Parent.INV

EC.MouseButton1Click:Connect(function()

Class.Text = "ECONOMY"

end)

PR.MouseButton1Click:Connect(function()

Class.Text = "PRIORITY"

end)

INV.MouseButton1Click:Connect(function()

Class.Text = "INVESTOR"

end)

But, when I click the button, It will not update other players’ views. Only my view.

Anyone can help me out?

2 Likes

It only updates for you since you’re the one who clicked it and changing the text locally which doesn’t affect the server, why you want to do is to use remote events.

When you click the gui, it fires the remote event to the server and the server fires the remote event to all clients, when a client sees the event triggered, it changes the text for that client which is every single client in the server since you fired the remote event to everyone.

Do you do It like this? I’m still new in this FireServer stuff. Mind if you give me an example?

I did it like this for one of the buttons.

EC.MouseButton1Click:Connect(function()
	Class.Text = "ECONOMY"
	Class.Text.Changed:Connect(function()
		game.ReplicatedStorage.ChangeText:FireServer(EC.Text)
	end)
end)
1 Like

yes, and make another server script that handles this remote event, and when the event is fired the server script fires the event back to ALL clients.
something like

game.ReplicatedStorage.ChangeText.OnServerEvent:Connect(function(player, text)
   game.ReplicatedStorage.ChangeText:FireAllClients(text)
end

( server script that handles the event, the first parameter is the player who fired the event to the server its a must to add that parameter, second parameter is the text the client fired )

I’m having an issue.

I will give more examples of what I’m doing.


image
image
I don’t know if I’m doing it right.

You need to have another event on your client event that fires whenever you fire all the clients it should look something like this:

game.ReplicatedStorage.ChangeText.OnClientEvent:Connect(function(text)
      Class.Text = text
end)

you could fire a remote event that makes the server change it
if you dont understand them roblox explained it really well here Remote Functions and Events

please keep in mind that the first variable on the server will always be the player who fired it, so if you fired some text, it would be player, text on the server

Updates the text to everyone.

Oh then that’s way easier
Make a remote event, when the PRIORITY button is clicked, the local script fires the remote event to the server. A server script that checks for when the remote event is fired will change the text of the surface gui.
local script:

button.MouseButton1Click:Connect(function()
   game.ReplicatedStorage.RemoteEvent:FireServer(text)
end)

server script:

game.ReplicatedStorage.RemoteEvent.OnServerEvent:Connect(function(player, text)
   surfaceGui.Text = text
end)

Thank you for helping me. It worked. I have another favor is this method the same for the use of images?

image
This didn’t work for image one. So I guess it has a different type of code?

I think so, if it doesn’t work try printing something inside the event and see if it prints. If yes, then it should be your gui’s problem. If no, then double check your event scripts.

please mark it as the solution then because some people might try to still help you