How do I make a GUI only open for people on a whitelist?

local LocalPlayer = Players.LocalPlayer
local RadioComms = game.StarterGui["Radio Comms"]
local Whitelist = {}

Players.PlayerAdded(function(player)
    if LocalPlayer.RadioComms.Enabled == true then
        if not table.find(Whitelist, LocalPlayer.UserId) then
            LocalPlayer.RadioComms.Enabled = false
        end
    end

That’s my code but it still leaves the gui completely open for everyone… I only want it open for certain people not everyone.

GUI:

3 Likes

Since you’re handling the gui on the client, you don’t need a player added event as the code will start running as soon as the local script has loaded.

local Player = Players.LocalPlayer
local Whitelist = {0, 3949484, USER_ID}

for i,v in ipairs(Whitelist) do
    if v == Player.UserId then
        --enable gui
    end
end

Also, just to remind you, since this is a local script, you need to be cautious as to what this Gui controls. Never let the client tell the server what to do!

1 Like

You have to use PlayerGui at this point to change visibility on the client.

local LocalPlayer = game.Players.LocalPlayer
local Whitelist = {}

game.Players.PlayerAdded(function(player)
     if LocalPlayer.PlayerGui:FindFirstChild("RadioComms").Enabled == true then
       if not table.find(Whitelist, LocalPlayer.UserId) then
         LocalPlayer.PlayerGui:FindFirstChild("RadioComms").Enabled = false
    end
end

but in my opinion, it would be better to set it at first closed and then enable it back if there is a whitelist userid in the table.

game.Players.Localplayer

or just Players.Localplayer? the one you put has the line under so

What I usually do is

local Players = game:GetService(“Players”)
local Player = Players.LocalPlayer

local player = game.Players.Localplayer

This should work to identify the local player.

Yours didn’t work either way so

Is there an error in the output?

Localscript or normal because the local script isn’t working for this because it just shows it to everyone

No; it literally just shows it

I just updated source code, put it in localscript inside startergui.

Is the gui initially disabled? The code I provided only works if the gui is disabled initially.

Inside the gui? or just inside the startergui

I just tested out this soruce code in studio and works. Put the localscript with next source code inside StarterGui.

local LocalPlayer = game.Players.LocalPlayer
local Whitelist = {}


if LocalPlayer.PlayerGui:WaitForChild("RadioComms").Enabled == true then
     if not table.find(Whitelist, LocalPlayer.UserId) then
         LocalPlayer.PlayerGui:FindFirstChild("RadioComms").Enabled = false
    end
end
1 Like

Hello!

My solution for enabling GUIs only for whitelisted players on client is this :

local player = game.Players.LocalPlayer
local whitelist = {
   [UserId] = true;
}

if whitelist[player.UserId] == true then
   --Enable gui here
end

Its better to use UserId since players can change usernames.

2 Likes

image

Enabled or disabled to begin with?

Do you have RadioComms inside StarterGui? Try to change WaitForChild to FindFirstChild. With Enabled as Default

I fixed it because there was a space between Radio and Comms

What about adding a group onto the whitelist though?

1 Like

You will have to use IsInGroup function to detect if player is inside group.

1 Like