Help with checking rank system

I want to make a rank system.

When I make it, it does not work. When I call my code.

None

I am making a rank system for allowed ranks on my admin commands (sorry if they are bad). But when I try to work with it and fix it, it does not work it says attempt to call a nil value. I am checking all the ranks I have for the admin and then the allowed ranks but it does not seem to work. (Sorry for not much detail)

for _, rank in pairs(allowedRanks) do
			if CommandsTable[cmdName] and Ranks[rank][Player.Name] then --errors here

				local args = {}

				for i = 2,#splitstring,1 do
					table.insert(args,splitstring[i])
				end

				CommandsTable[cmdName](Player,args)
				
			elseif not Ranks[rank][Player.Name] then --errors here
				table.insert(Ranks.NoRank,Player.Name)
				return nil
			end
		end
    end)
end)
local Ranks = {
	["Owner"] = {"FreeFlyHaker56","PlayerName"};
	["Co-Owner"] = {"PlayerName"};
	["SuperAdmin"] = {"PlayerName"};
	["Admin"] = {"PlayerName"};
	["Mod"] = {"PlayerName"};
	["NoRank"] = {"PlayerName"};
}

local allowedRanks = {
	"Owner";
	"Co-Owner";
	"SuperAdmin";
	"Admin";
	"Mod";
}

Which line does it say is attempting to call a nil value?

165 :grinning_face_with_smiling_eyes: :grinning_face_with_smiling_eyes:

It will error on the other since it is the same thing

Can you please paste line 165 so I can see it?

if CommandsTable[cmdName] and --[[Ranks[rank][Player.Name]]] then errors commented part

oh I’m sorry I didnt see where you put that there were errors there on the original post, but let me check it out and see what I can find

1 Like

Basically, you can’t call a value in a table and see what it’s key is. So you can do Ranks[rank] and get a list of all of the players, but you can’t do Ranks[rank][Player.Name] because the player name is a value of the rank. You can fix this with a function:

local function getPlayersRank(player)
	for _, p in pairs(Ranks[rank]) do
		if p = player.Name then
			return true
			break
		end
	end
	return false
end

and on that line you would put:

if CommandsTable[cmdName] and gatPlayersRank(Player) then

I believe this will work, if not tell me what is wrong and I will try to fix it :slight_smile:

1 Like

I had to fix a little since you cannot say return then break

Oh I am sorry that is my fault

How would I check if they are not an allowed rank NoRank is not an allowed rank so they cannot use commands

It did not work for me :frowning:

You could use the same function except put “NoRank” for the rank. After looking at that script there is a few things I messed up on let me fix it real fast

here are the tables:

local Ranks = {
	["Owner"] = {"FreeFlyHaker56","PlayerName"};
	["Co-Owner"] = {"PlayerName"};
	["SuperAdmin"] = {"PlayerName"};
	["Admin"] = {"PlayerName"};
	["Mod"] = {"PlayerName"};
	["NoRank"] = {"PlayerName"};
}

local allowedRanks = {
	"Owner";
	"Co-Owner";
	"SuperAdmin";
	"Admin";
	"Mod";
}

I am a little confused, what is the AllowedRanks table for?

AllowedRanks is used so that only those ranks can use commands

Ok let me redo the script and I may be able to get it working

1 Like
local function isPlayerAllowed(rank, player)
	for i, p in pairs(Ranks) do
		wait()
		for _, v in pairs(Ranks[p]) do
			wait()
			if v == player.Name then
				if i <= allowedRanks[rank] then
					return true
				end
			end
		end
	end
	return false
end

The way this should work is you enter the allowed rank first (ex: “Admin”) and the player second. It should then figure out what rank the player is and then it should check if they have the same or better rank. If there are any errors let me know but I believe that it should work now.

rank is allowedRanks it is this:
for _, rank in pairs(allowedRanks) do

image