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