Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
1

How can I make a GUI appear for everyone in a server?

Asked by 6 years ago
Edited 5 years ago

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!

0
The last example of this blog post fits what you want, but of course a few modifications will need to be made. User#24403 69 — 6y
0
:connect is deprecated use :Connect instead User#23989 0 — 6y
0
in server scripts, i've gotten it to work with a for loop DeceptiveCaster 3761 — 6y

2 answers

Log in to vote
0
Answered by
yHasteeD 1819 Moderation Voter
6 years ago
Edited 6 years ago

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! :)

0
Thank you :D Now I will know how to do this in the future! Avia_Robby 42 — 6y
Ad
Log in to vote
0
Answered by
joeldes 201 Moderation Voter
6 years ago

Here's how you would do this.

Option 1:

First make a RemoteEvent and place it in ReplicatedStorage. From there you will need two scripts.

  1. A LocalScript inside your GUI or somewhere on the client

  2. 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.

Option 2:

  1. Make a RemoteEvent that is fired when the player clicks the GUI button.

  2. 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.

1
The server cannot access the PlayerGui's descendants unless they were placed by the server. Even if the server did place the GUIs in there the server shouldn't be changing the visibility. It makes no sense for the server to change a 2D element where only one player will see. User#24403 69 — 6y
0
You'll want a RemoteEvent listening for the OnClientEvent instead, and the server fires the event. User#24403 69 — 6y
0
Not a whole lot of this reply makes sense. OnServerEvent is a SERVER exclusive event - yet you seem to be trying to use it from the client. Additionally, and as incapaz stated before - the server cannot access anyone's PlayerGui. Also, always nullify index if you are not going to use it, don't create a pointless variable SummerEquinox 643 — 6y

Answer this question