Problem with Table

Hello Developers!

I’m currently making an admin script, which is almost finished, but when I wanted to make an :unadmin command I ran into this problem; I want to check if the player is an admin, which worked before but because I’m using a different method now it doesn’t work anymore. I also want to remove the player’s UserId from the table whenever someone types :unadmin {name}, which also doesn’t work. I hope this is enough info, let me know if you need some clarification!

Useful variables:

	local lowerMsg = string.lower(msg)
	local splittedString = string.split(lowerMsg, " ")
	local command = splittedString[1]
	local target = splittedString[2]
    local ModuleScripts = script.Parent.Parent:WaitForChild("ModuleScripts")
    local admins = require(ModuleScripts:WaitForChild("Administration"))

Check if the player is admin:

local function playerIsAdmin(player)
	
	for i, v in pairs(admins) do
		print(v) -- Prints the correct value
		if v == player.UserId then -- Somehow false??
			
			return true
			
		end
		
	end
	
end

Remove from admin table:

		elseif command == cmdPrefix.."unadmin" then
			
			local playerToDemote = checkForPlayer(target)
			
			if playerToDemote ~= nil then
				for i, v in pairs(admins) do
					if v == playerToDemote.UserId then
						table.remove(admins, i)
						printAdminList()
					end
				end
			end

Admins Table: (ModuleScript)

local Administration = {

	"67792130"; -- Rowan_Scripts
	"133492854"; -- Iovehxrtss
	"604873370"; -- LorenzoNL2580
 
}

return Administration
1 Like

You have entered strings into the Administration table.
Use tostring() on the if statement:

if v == tostring(player.UserId) then
1 Like

I don’t know why I didn’t think about that. Well, thanks for your help!

Sicne you’re using a array, I recommend using ipairs instead of pairs.

1 Like

I’m doing it like this now:

local Administration = {

	["67792130"] = "Rowan_Scripts";
	["133492854"] = "Iovehxrtss";
	["604873370"] = "LorenzoNL2580";
 
}

return Administration

And I have another issue. I can’t figure out how to remove the player from the table!
Here’s the script:

for i, v in pairs(admins) do

	if i == tostring(playerToDemote.UserId) then
			
		table.remove(admins, i)
			
	end
		
end

what does the admins table look like?

It’s at the top of my last comment, it’s in a ModuleScript.

To add players, you can do:

Table[UserId] = Name -- local Table = {[UserId] = Name}

To remove players, you can do:

Table[UserId] = nil -- local Table = {}
1 Like