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 3 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 — 3y

3 answers

Log in to vote
1
Answered by
raid6n 2196 Moderation Voter Community Moderator
3 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.

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

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

local Players = game:GetService("Players")
Players.PlayerAdded:Connect(
    function(plr)
        print(plr.Name .. " has joined.")
    end
)

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

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

Okay, now let's combine everything:

local whilelistedplayers = {"Player1", "Player2"}
local Players = game:GetService("Players")
Players.PlayerAdded:Connect(
    function(plr)
        print(plr.Name .. " has joined.")
        for i, v in pairs(whilelistedplayers) do
            if v == plr.Name then
                local Gui = game.ServerStorage.Gui:Clone()
                Gui.Parent = Player.PlayerGui
            end
        end
    end
)

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 — 3y
Ad
Log in to vote
2
Answered by 3 years ago
Edited 3 years ago

Here is an explanation to understand.

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

--> Services
local Players = game:GetService("Players")
local ServerStorage = game:GetService("ServerStorage")

--> Variables
local Whitelist = {"Oof1", "Oof2", "Oof3"} --> You can use ID instead of names

--> Functions
local function CheckWhitelist(Player)
    for Index, Value in pairs(Whitelist) do
        if Player.Name == Value or Player.UserId == Value then
            return true
        end
    end
end

--> Methods
Players.PlayerAdded:Connect(function(Player)
    if CheckWhitelist(Player) then
        local Gui = ServerStorage.Gui:Clone()
        Gui.Parent = Player.PlayerGui
    end
end)

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 — 3y
0
Oh, I forgot. I asked this for help with my spectate button, so would you have any help on that? TheEggsquidzidBoi 38 — 3y
Log in to vote
0
Answered by 3 years ago
Edited 3 years ago

I think you can do

if game.Players.LocalPlayer.Name == "YourName" then
    script.Parent.Enabled = true
else
    script.Parent.Enabled = false
end

and if you want to do multiple players then do this

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

Answer this question