Making a GUI disappear

Hi, how do I make it so that the GUI disappears for all players? Here is my code:

	for z, c in pairs(game.Players:GetPlayers()) do
		local Shop = game.StarterGui.ShopGUI
		Shop.Enabled = false
	end

Thank you for the help!

1 Like

StarterGui is just a template. Changing it in-game wouldn’t change it for the rest of the players. Also I would suggest refraining from this method and using RemoteEvents (as the person below mentioned) instead and handle the rest in the client after the event was fired. This is because with your current script, if a player leaves while your code is running, the script will break.

for _, v in ipairs(game:GetService("Players"):GetPlayers()) do
	local Shop = v.PlayerGui.ShopGUI
	Shop.Enabled = false
end

Here is a good tutorial by @ChipioIndustries which may help as it is explained in more detail.

You should really use a remote for that too

although you should’ve handled Ui on the Client, to disable everyone’s Gui do this:

  local Players = game:GetService("Players")

  for _, player in ipairs(Players:GetPlayers()) do
           local playerGui = player:FindFirstChild("PlayerGui")
           local gui = playerGui.ShopGui
     gui.Enabled = false
  end

@Scripted_Vortex , @WooleyWool Do not iterate through pairs even though it might ‘work’ , loop through ipairs.

What’s the difference between in pairs and in ipairs?

This thread i found may help you understand the difference.

pairs is built to be used for iteration over dictionaries, ipairs for contiguous arrays with numerical indices.

There’s more