How do I make a gui appear for everyone in the server when I click a button?

I have basic scripting knowledge and know-how things work, but I have some problems with this, if anyone could help I would appreciate it. I want the GUI to appear to everyone when clicking a button. If you need more info just ask me, I already got the UI set up.

5 Likes

You can clone it into every player gui by using getchildren

2 Likes
for i,player in pairs(game:GetService("Players"):GetPlayers())do
    player.PlayerGui:WaitForChild("GuiName").Enabled = true
end
5 Likes

this only if you have the gui into the starterGui pack

2 Likes

Is this in a script.Parent.MouseButton1Click:Connect(function() ?

2 Likes

yes , but into a server script

2 Likes

if it is a local script you have to fire a remote event and handle players gui from server side

2 Likes

Mind if you give me the whole script, with the mousebutton1click? I’m kinda new to all this.

2 Likes

is the script local or a normal server script

2 Likes

It’s local but I maybe can change.

2 Likes

You can only register when a tool is clicked in a local script. Changes for other players must be handles on the server. Therefore, the only way to accomplish your goal is by using remote events. You register when its clicked with a local script, then notify the server. The server will then receive the event and make all the player’s guis visible.

2 Likes

Fire an event from the localscript when the clickdetector is clicked or however you want,

Event:FireServer()

On the server you would do

Event.OnServerEvent:Connect(function()
       GUI.Enabled = true    --- GUI ENABLE HERE
end)
2 Likes

local script

script.Parent.MouseButton1Click:Connect(function()
     RemoteEvent:FireServer()
end)

then in server

     RemoteEvent.OnServerEvent:Connect(function(player_)
        for i,player in pairs(game:GetService("Players"):GetPlayers())do
           player.PlayerGui:WaitForChild("GuiName").Enabled = true
       end
    end)
5 Likes

i recommend you visiting Remote Functions and Events (roblox.com) for more infos

1 Like

Do I need to make a “Remove Event” and what should I name it?

1 Like

you can choose the name . Add it into Replicated Storage

1 Like

The script also?

Like both? The script and the removeevent?

1 Like

remote into replicated , than the server script into server script service

1 Like

Alright, There is a few things to add here so lets get started.

  1. Add a event into ReplicatedStorage, Name it whatever you want but mind it so you refrence that name in you’re local script.

  2. Once you’ve did that put in a local script in StarterGui, setup a connection as so:

YourObject.MouseButton1Click:Connect(function()
    game.ReplicatedStorage.RemoteEvent:FireServer()
end)
  1. Almost there, Create a server script in ServerScriptService inside it do:
game.ReplicatedStorage.RemoteEvent.OnServerEvent:Connect(function(Player)
     for i,v in pairs(game.Players:GetPlayers())
       local GUI = -- Location to you're GUI
       Gui:Clone().Parent = v.PlayerGui
   end
end)

That’s it!, But I really do suggest reading up on some tutorials:

RemoteEvent (roblox.com)

1 Like

Explanation

So, first you need to understand the GetChildren() and GetPlayers() function. After this, you need to understand the importance of Client to Server and Server To Client actions. I assume you understand this part already but if you don’t, you can use Remote Events & Functions to communicate with a Server Script from the client.

Answer

Now, to answer your question; it depends on how you want to have the GUI inserted into the player. No matter what, you need to have a RemoteEvent/Function set-up. No matter what, just enabling something in the StarterGUI through the Server will not enable it for everyone else. So, its best to reference it through the Players custom Folder PlayerGui. This is where everything in StarterGui gets cloned to.

Server Script

--/Made By MillerrIAm\--
--/Script\--
local Event = game.ReplicatedStorage.RemoteEvent

Event.OnServerEvent:Connect(function(plr,GUIName)
	for index,player in pairs (game.Players:GetPlayers()) do 
		--You can enable a GUI through their PlayerGui Folder, as long as it's in StarterGui and you have `ResetOnRespawn` on, you'll be fine, else you'll have to add it again if ever removed.
		if player.PlayerGui:FindFirstChild(GUIName) then
			player.PlayerGui[GUIName].Visible = true --Use this if it's a Frame
			player.PlayerGui[GUIName].Enabled = true --Use this if it's a ScreenGUI
		else
			local GUI = game.ServerStorage[GUIName]:Clone()
			GUI.Parent = player.PlayerGui
			GUI.Enabled = true --Use this if it's a ScreenGUI
			GUI.Visible = true --Use this if it's a Frame
		end
	end
end)

Local Script

Place this into the button.

--/Made By MillerrIAm\--
--/Script\--
local Event = game.ReplicatedStorage.RemoteEvent
script.Parent.MouseButton1Click:Connect(function()
	Event:FireServer("GUIName") --[[Remember, even though you aren't sending it yourself, the first variable will always be the player triggering/sending this signal to the RemoteEvent. I'm assuming you put your local script into the button you're using.]]
end)

2 Likes