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.
You can clone it into every player gui by using getchildren
for i,player in pairs(game:GetService("Players"):GetPlayers())do
player.PlayerGui:WaitForChild("GuiName").Enabled = true
end
this only if you have the gui into the starterGui pack
Is this in a script.Parent.MouseButton1Click:Connect(function()
?
yes , but into a server script
if it is a local script you have to fire a remote event and handle players gui from server side
Mind if you give me the whole script, with the mousebutton1click? I’m kinda new to all this.
is the script local or a normal server script
It’s local but I maybe can change.
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.
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)
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)
Do I need to make a “Remove Event” and what should I name it?
you can choose the name . Add it into Replicated Storage
The script also?
Like both? The script and the removeevent?
remote into replicated , than the server script into server script service
Alright, There is a few things to add here so lets get started.
-
Add a event into ReplicatedStorage, Name it whatever you want but mind it so you refrence that name in you’re local script.
-
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)
- 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:
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)