UserId GUI access

I’m trying to get a UserId system to detect whether a user can have access to an admin panel or not in a local script.

I’m trying to have this happen:
trying to have happen
But this is what happens instead:
what actually happens

So far I’ve tried

game.Players.PlayerAdded:Connect(function(plr)
	game:GetService("Players")
	if plr.UserId == 1161714789 then
		script.Parent.Visible = true
	else
		script.Parent.Visible = false
	end
end)
local allowed = ("CLS0211")

game.Players.PlayerAdded:Connect(function(plr)
	for i, v in pairs(allowed) do
		if plr.Name == v then
			script.Parent.Visible = true
		end
	end
end)
game.Players.PlayerAdded:Connect(function(plr)
	if plr.Userid == 1161714789 then
		script.Parent.Visible = true
	else
		script.Parent.Visible = false
	end
end)

What am I doing wrong?

Your code will change when a new player enters the server. Because it is a LocalScript, you can use LocalPlayer

local plr = game:GetService("Players").LocalPlayer
local UserIds = {1161714789}
script.Parent.Visible = (table.find(UserIds, plr.UserId) ~= nil)

Note that you must place a similar check on the server, because it is easy to access for exploiters.

1 Like

Just so you know this is how to propery define a table:

local allowed = {'CLS0211'}

It uses curly braces instead of brackets because it likes to be quirky.
And if you have different types of admin I recommend doing a dictionary:

local dictionary = {
['Admins'] = {'USer1','User2'},
['Mods'[ = {'User3','User2'}
}

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.