If statement problems on admin system

I’ve recently scripted an admin system for my own game, right? Everything was working just fine until this very moment where players magically got the ability to use commands for absolutely no reason. Keep in mind, no changes were made to the script.

In order for the script to know if you’re in the according group rank to use the admin command it runs a function.

local function Check(player) -- Will check the player's permission to use certain commands.
	
	local usedp = game.Players[player]
	local perm = usedp:GetRankInGroup(group)

	if perm >= 249 and perm < 251 then -- Mod In-Training ~ Moderator
		return 1
	elseif perm >= 251 and perm < 252 then -- Admin
		return 2
	elseif perm >= 252 or player == 'Player1' then -- Head Admin+ 	
		return 3
	elseif perm < 249 then
		return 0
	end	
end

Keep in mind that this is the hierarchy

local mods = 1
local admins = 2
local sadmins = 3
local none = 0

Alright, so every time someone attempts to run a command, it Checks for their group rank to see if they’re equal or above that certain role.

elseif cmd == ':speed' or cmd == ':ws' and Check(player.Name) >= mods then

print('running this command on ' .. player.Name .. " cause he's a " .. Check(player.Name) .. " in this group " .. tostring(group))

local target = Fill(arg1)
local newspeed = table.remove(command, 1)

game.Workspace[target].Humanoid.WalkSpeed = newspeed

admin_logs:post{['content'] = player.Name .. '** has altered** ' .. target .. "**'s speed to** " .. newspeed}

Welp, I tried debugging this in multiple ways, I changed the group ID to 1 and attempted to do the command, here’s what the print() function return. Screenshot: Screenshot by Lightshot

What the code is saying is that I’m a permission 0 therefore I’m not above or equal to 1, as it’s required to pass the if statement. Could anyone think of any possible problem that could be happening here?

Check the boolean logic here:
elseif cmd == ':speed' or cmd == ':ws' and Check(player.Name) >= mods then

This condition is met if:

  • cmd == ‘:speed’
    OR
  • cmd == ‘:ws’ and Check(player.Name) >= mods

Just needs some paranthesis

3 Likes

I’m pretty sure that this will run like this

cmd == ':speed' or (cmd == ':ws' and Check(player.Name) >= mods)

as a side note, this implies that your players should only be able to use the speed command. You said players can use commands - are there any other ones that players happen to be able to use?

1 Like

Just:

elseif (cmd == ':speed' or cmd == ':ws') and Check(player.Name) >= mods then

Typically I use parenthesis for if statements anyway to avoid problems like these, plus I’m just use to using them. Makes the code more organized and readable.

2 Likes