Why is this not registering the UserID for this special command?

The Goal

I want this to admin the people with the UserIds inside the table.

The Issue

It doesn’t register the UserId, nor does it give the user the permission to access this command.

What I tried

Nothing, as I don’t know where to edit nor the actual error in my script. I know I could link it to a username but Usernames change too often, hence why I’m aiming for the UserId.

The Script

--Made By MillerrIAm
local SFXSystem = require(script.Parent.SFXs)
local Admin = false
local admins = {678299}
--------Main Code------
	for i,v in pairs (admins) do
		if v[plr.UserId] then
			Admin = true
		if Admin then
			if msg == "true" then

Final Note

I also tried using v == plr.UserId and it gave the command to everyone…
Thank you to anyone who looks at this and attempts to help me solve this issue.

1 Like

It looks like you are using a shared variable “Admin” For all users
So If the latest person to join the server has admin it will allow any user to run the command
v == plr.UserId should be the correct check
If you instead store the Admin variable under the Player Joined Event it will keep the variable local to that event


v == plr.UserId was correct, however, you need to move your local Admin = false inside the PlayerAdded function. This makes the variable only accessible to the current instance of the function; not every time the function is run.


First of all, admins is going to be an array, (keys of 1, 2, 3, etc.) so you can change pairs to ipairs.

Second, i is the key and v is the value, so you want to say v == plr.UserId.

Third, you have local variable Admin outside of the PlayerAdded event function, so if one person is an admin and sets that variable to true, it will stay true and all following players who join will be admin. You want to move this variable into the function so that there will always be a new Admin variable (that equals false) whenever the function is ran.