Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
✓ ANSWER ACCEPTED

How would I make this update other player's GUI's?

I have a script to open and close curtains and then realised the GUI wont update for other player's with the GUI, is there any way to update all player's GUIs if someone opens the curtains and closes them? The GUI format is like this:

CurtainControls (Screen GUI)
	Collapse(TextButton)
		Main(Script)
	Curtains(TextButton)
		Main(Script)

My script is below how would I make this update to other player's GUIs aswell but not all players get the GUI it is given to certain players through another script.

Open = false
DB = false

script.Parent.MouseButton1Click:connect(function()
	if Open == false and DB == false then
		DB = true
		game.Workspace.Part.Open.Disabled = false
		script.Parent.Text = "Opening..."
		for i = 1,250 do
			wait(.00001)
		end
		game.Workspace.Part.Open.Disabled = true
		Open = true
		script.Parent.Text = "Opened"
		wait(1)
		script.Parent.Text = "Close Curtains"
		DB = false
	elseif Open == true and DB == false then
		DB = true
		game.Workspace.Part.Close.Disabled = false
		script.Parent.Text = "Closing..."
		for i = 1,250 do
			wait(.00001)
		end
		game.Workspace.Part.Close.Disabled = true
		Open = false
		script.Parent.Text = "Closed"
		wait(1)
		script.Parent.Text = "Open Curtains"
		DB = false
	end
end)

1 answer

✓ Accepted answer

Try using BindableFunction or RemoteFunction; read about those on the wiki for all the details, but I will show you an example tailored to your problem.

Instead of setting the text directly, hook up a RemoteFunction that set's everyone's text, by detecting if they have the GUI in their PlayerGui /their GUI is active.

That may look like this:

function findEveryonesGuiAndChangeItIfTheyHaveIt()
	local players = game.Players
	for index,player in pairs(players) do
		if player.PlayerGui:FindFirstChild("NameOfGuiWeWantToChange") then
			local gui = player.PlayerGui:FindFirstChild("NameOfGuiWeWantToChange")
			--[[
				... manipulate the ScreenGui of the player here by referencing the variable 'gui'.
			--]]
		end
	end
end

Pretty much, we iterate over all the players and run a test on them. If they contain something called NameOfGuiWeWantToChange in their PlayerGui, we store that something in a variable called gui. It's a pretty safe bet that your ScreenGui will have a different name than anything else in there, so gui is most likely storing your ScreenGui.

  • CashRP2

This discussion is preserved as it was. New answers, comments, and votes are closed.