Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
COMMUNITY QUESTION

Can I get help with an opening an admin GUI??

I was messing around and had the idea to make an admin GUI. All I need to figure out is the admin script to customize the admins. Here's what I came out with:


--Please put in their ID for it to work

 local Admins = {138149463,}


-- No touchy :)
local Players = game:GetService("Players")

local function onPlayerAdded(newPlayer)
	if newPlayer.UserId == Admins then 
		script.Parent.AdminPanel.Visible = true
	end
end
if script.Parent.Credit.Value == "robolol788" then
	else script.Parent:Destroy()
end
Players.PlayerAdded:Connect(onPlayerAdded)

I have no errors in the output. Help!

1 answer

The problem appears on line 10, if newPlayer.UserId == Admins then. UserId is a number value while Admins is an array from the table you defined on line 3. Therefore, you can't compare them to each other because they won't ever be equal. What you have to do instead is iterate through the Admins table and compare its values with the UserId. A good way to iterate through tables is the built-in pairs() function in a for loop, like this:

for i, value in pairs(Admins) do
	if value == newPlayer.UserId then
		script.Parent.AdminPanel.Visible = true
	end
end

This should solve this specific problem, but from the looks of your script there may also be other problems regarding client-server communication. GUI manipulation is best done on the client, in a LocalScript. However, checking important things like whether or not the player is an admin, should be done on the server in a Script. You should use a RemoteEvent to pass this information from the server after having done the check, to the client in order to properly configure the GUIs.

This discussion is preserved as it was. New answers, comments, and votes are closed.