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

How to make GUI visible to certain players?

Asked by 4 years ago

Yes, I know its on the Roblox Dev Forum, but I couldn't seem to understand it.

If anyone could explain a bit easier, it would surely help!

0
I can understand you, do you want a white list of who can use a specific Gui? User#37171 0 — 4y

3 answers

Log in to vote
1
Answered by
raid6n 2196 Moderation Voter Community Moderator
4 years ago

Here's a script and explanation that minifies @GR1PP3RTV

First, let's make a table holding all the players that will see the GUI.

1local whilelistedplayers = {"Player1", "Player2"}

Once you do that, we'll have to make a PlayerAdded Event

1local Players = game:GetService("Players")
2Players.PlayerAdded:Connect(
3    function(plr)
4        print(plr.Name .. " has joined.")
5    end
6)

After that, we'll have to loop through the table to detect if the player who joined is in the table.

1for i, v in pairs(whilelistedplayers) do
2    if v == plr.Name then
3        local Gui = ServerStorage.Gui:Clone()
4        Gui.Parent = Player.PlayerGui
5    end
6end

Okay, now let's combine everything:

01local whilelistedplayers = {"Player1", "Player2"}
02local Players = game:GetService("Players")
03Players.PlayerAdded:Connect(
04    function(plr)
05        print(plr.Name .. " has joined.")
06        for i, v in pairs(whilelistedplayers) do
07            if v == plr.Name then
08                local Gui = game.ServerStorage.Gui:Clone()
09                Gui.Parent = Player.PlayerGui
10            end
11        end
12    end
13)

How the code functions:

When a player joins, the i, v in pairs loop would detect if the player who joined name is one of the whitelisted players. If yes, it would clone the GUI and put it in the PlayerGui. (make sure the Gui that will be cloned is inside ServerStorage

0
This also helps as well. Thanks! TheEggsquidzidBoi 38 — 4y
Ad
Log in to vote
2
Answered by 4 years ago
Edited 4 years ago

Here is an explanation to understand.

Gui will be on the ServerStorage, so exploiters can't access Gui very easily.

01--> Services
02local Players = game:GetService("Players")
03local ServerStorage = game:GetService("ServerStorage")
04 
05--> Variables
06local Whitelist = {"Oof1", "Oof2", "Oof3"} --> You can use ID instead of names
07 
08--> Functions
09local function CheckWhitelist(Player)
10    for Index, Value in pairs(Whitelist) do
11        if Player.Name == Value or Player.UserId == Value then
12            return true
13        end
14    end
15end
View all 23 lines...

As you can see, I created a table that contains the names of who can use the Gui, and a function called CheckWhitelist. The first argument of the function is the player object, and the function check if table values matches the player's name or ID.

So, the PlayerAdded method of Players service, will fire when a player joins the server. After the method fire, I use the CheckWhitelist function to check if the player's name or ID is in table values, if so, will clone the Gui and set the Parent to the PlayerGui of the player.

I guess this can help you.

0
This helps me considerably. Thanks! TheEggsquidzidBoi 38 — 4y
0
Oh, I forgot. I asked this for help with my spectate button, so would you have any help on that? TheEggsquidzidBoi 38 — 4y
Log in to vote
0
Answered by 4 years ago
Edited 4 years ago

I think you can do

1if game.Players.LocalPlayer.Name == "YourName" then
2    script.Parent.Enabled = true
3else
4    script.Parent.Enabled = false
5end

and if you want to do multiple players then do this

1if game.Players.LocalPlayer.Name == "YourName", "theotherguysname", "otherguysname" then
2    script.Parent.Enabled = true
3else
4    script.Parent.Enabled = false
5end

Answer this question