Tonumber() returning <= nil error message

Hi, my role script is returning the following error: Attempt to compare number <= nil on line 23. Any help is appreciated.

The output:

Code:

local conf = require(script.Parent.Parent["Beta Features"])
local prefix = conf.prefix
local superadmins = conf.admins.Superadmins
local admins = conf.admins.Admins
local mods = conf.admins.Mods
local joinlog = conf.joinlog
local debuggers = {"Player1"}
local role = ""
local rank = ""
local kick = conf.commands.Kick
local kmsg = kick.Message
local ksadmin = kick.ShowAdmin
local krole = kick.Level

game.Players.PlayerAdded:Connect(function(plr)
        if table.find(superadmins, plr.Name) then role = 3 rank = "Superadmin" if joinlog then warn("[Log][Joins][Basic Mod]: "..plr.Name.." ("..rank..") joined the game") end
	    elseif table.find(admins, plr.Name) then role = 2 rank = "Administrator" if joinlog then warn("[Log][Joins][Basic Mod]: "..plr.Name.." ("..rank..") joined the game") end
	    elseif table.find(mods, plr.Name) then role = 1 rank = "Moderator" if joinlog then warn("[Log][Joins][Basic Mod]: "..plr.Name.." ("..rank..") joined the game") end
	    elseif table.find(debuggers, plr.Name) then role = 3 rank = "Superadmin" if joinlog then warn("[Log][Joins][Basic Mod]: "..plr.Name.." ("..rank..") joined the game") end
	end
	plr.Chatted:Connect(function(msg)
		print(plr.Name .. " "..role)
		if tonumber(role) >= 3 then
			print("allowed")
			else
			print("not allowed")
		end
	end)
end)

I would try setting role and rank to -1 instead of ""

I found the solution, I changed the role variable to 0 instead of a string, it works fine now.
Thanks alot for the help tho!

If this isn’t your script, find something else like Kohl’s admin (Scripth’s Admin) because this is bad. [I’m assuming you are looking for an admin script which is commonly already available in Toolbox aka free models]

I’ll just say it’s likely your Superadmin/Admin/Mod or whatever will join a game and they and everyone in the server will get that privilege. And then 1 more normal player will join and everyone in the server will lose said privilege.

I’ve noticed this, do U have a recommendation how how to make it so only the player that has admin gets the role number?

Change this:

To this:

game.Players.PlayerAdded:Connect(function(plr)
        local role, rank = role, rank
        if table.find(superadmins, plr.Name) then role = 3 rank = "Superadmin" if joinlog then warn("[Log][Joins][Basic Mod]: "..plr.Name.." ("..rank..") joined the game") end
	    elseif table.find(admins, plr.Name) then role = 2 rank = "Administrator" if joinlog then warn("[Log][Joins][Basic Mod]: "..plr.Name.." ("..rank..") joined the game") end
	    elseif table.find(mods, plr.Name) then role = 1 rank = "Moderator" if joinlog then warn("[Log][Joins][Basic Mod]: "..plr.Name.." ("..rank..") joined the game") end
	    elseif table.find(debuggers, plr.Name) then role = 3 rank = "Superadmin" if joinlog then warn("[Log][Joins][Basic Mod]: "..plr.Name.." ("..rank..") joined the game") end
	end

This creates 2 new local variables (role and rank) inside the namespace of the function connected to PlayerAdded. Whenever you try to edit/read those variables inside said namespace, it will index the local variables instead of the global ones.

I’ve just modified the script, but I’m unsure how to add the if statement for if the player has the role number or not.

I think it looks fine if you add

local role, rank = role, rank

and change role to 0, which is what solved your problem to begin with
also you can remove tonumber(role) since role is a number already.

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.