The script I made works but it only changes locally. I have heard that I need to use FireAllClients for this but I am not exactly sure how it works.
script.Parent.MouseButton1Down:connect(function() script.Parent.Parent.Parent.NoGame.Visible = false script.Parent.Parent.Parent.Waiting.Visible = true end
If someone could explain to me how I could implement FireAllClients into this script so that it changes the GUI for everyone in the server that would be great. Thanks in advance!
As you yourself said, this can be done with :FireAllClients()
, if you want to learn more about it you can have a look here: Roblox Wiki Page - Fire All Clients
For this you also need to know a bit about Server Event. You can find this in roblox wikia: Roblox Wiki Page - OnServerEvent
You can also learn more about RemoteEvents, just click here: Roblox Wiki Page - RemoteEvents
You must first use a RemoteEvent
Create a RemoteEvent
and put on ReplicatedStorage, name this as Event (You can choose the name, but if you do not want to edit the script you can leave it with that name that I said.)
Create a Script (Server Script)
in ServerScriptService
And put this code:
local event = game.ReplicatedStorage.Event -- Location of event event.OnServerEvent:Connect(function(plr,name) -- On fireserver get player and whitelist name. if plr.Name == (name) then -- If player name is in whitelist names game.ReplicatedStorage.Event:FireAllClients(plr); -- Fire all clients. else plr:Kick("Do not use exploits!") end end)
Now create a LocalScript
And put LocalScript in your button. and put this code:
-- Local Script -- repeat wait() until game.Players.LocalPlayer -- Not return nil for Player (Works in LocalScript.) local whitelistname = {"Avia_Robby"} -- Put your name here local Player = game.Players.LocalPlayer -- Get Current player local client = game:GetService("ReplicatedStorage").Event -- Get Event client.OnClientEvent:Connect(function(plr) -- On fire all clients for i,v in pairs(game:GetService("Players"):GetPlayers()) do -- Get all players script.Parent.Parent.Parent.NoGame.Visible = false -- Set NoGame for visible false script.Parent.Parent.Parent.Waiting.Visible = true -- Set Waiting for visible true end end) script.Parent.MouseButton1Click:Connect(function() -- On click with button for i,v in pairs(whitelistname) do -- Get whitelist names if Player.Name == v then -- If player name are in whitelist client:FireServer(v); -- Fire Server end end end)
:FireAllClients()
can only be used by the server, then I made a connection with the server, and the server gives :FireAllClients()
and all players will receive the GUI, Why will they receive the GUI? Because when giving FireAllClients you have access to all items of the PlayerGUI because the Client have the GUI's then you have access to everything and can change things.
Not works? tell-me on comments
Good luck in your game! :)
Here's how you would do this.
First make a RemoteEvent
and place it in ReplicatedStorage
. From there you will need two scripts.
A LocalScript
inside your GUI or somewhere on the client
A Server Script
that will be firing at the clients.
ServerScript
game.ReplicatedStorage.RemoteEvent:FireAllClients()
LocalScript
game.ReplicatedStorage.RemoteEvent.OnServerEvent:Connect(function() script.Parent.Parent.Parent.NoGame.Visible = false script.Parent.Parent.Parent.Waiting.Visible = true end)
The issue with this method is that based on your needs, it seems that you would also need a RemoteEvent
that is called when the player presses the GUI button you seem to have. Sooooooo... Here is another way that some devs may find not as good but I think works fine.
Make a RemoteEvent
that is fired when the player clicks the GUI button.
When fired loop through all the players and enable the GUI (assuming the players already have the gui object in their PlayerGui folder)
for i,player in pairs(game.Players:GetPlayers()) do player.PlayerGui.NameOfGui.Enabled = true end
I hope this helped, if you liked the answer please give me some rep by upvoting and checking it off as correct.