Ad
Still have questions? Join our Discord server and get real time help.
Log in to vote
1

How to make GUI visible to certain players?

Asked by 22 days 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? GR1PP3RTV 52 — 22d

3 answers

Log in to vote
1
Answered by
raid6n 2119 Moderation Voter Community Moderator
22 days 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 — 22d
Ad
Log in to vote
2
Answered by 22 days ago
Edited 22 days 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 — 22d
0
Oh, I forgot. I asked this for help with my spectate button, so would you have any help on that? TheEggsquidzidBoi 38 — 22d
Log in to vote
0
Answered by
RareBIue 133
22 days ago
Edited 22 days 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