Comparing a nil <= number

Hello,

I’ve ran into error that’s confusing to me that I don’t really get how I’ll resolve it. When running a command it with no subject linked to it like… (:refresh) it would give me a Comparing a nil <= number on line 467. I’m not sure why this is happening nor how to fix it. Please help me if you can. Thank you.

  • Line 467
if Lvl >= Table.Level then
  • Entire Script
local Module = {}
-- Services --
local Players = game:GetService('Players')
local ReplicatedStorage = game:GetService('ReplicatedStorage')
local RunService = game:GetService('RunService')
local ServerStorage = game:GetService('ServerStorage')
local Teams = game:GetService('Teams')
local TxtService = game:GetService('TextService')
-- Variables --
local Tools = ServerStorage.Assets:FindFirstChild('Tools')
----

-- Settings / Configuraton --
local Prefix = ':'
local Seperator = ' '
local ArguementSeperator = '/'
local ServerLocked = false
----

-- Admin Levels --
local NoAdminLvl = 0
local ModLvl = 1
local AdminLvl = 2
local SuperAdminLvl = 3
local OwnerLvl = 4
local CreatorLvl = 5
----

-- Tables --
local Admins = {
	Plrs = {
		['1588035760'] = CreatorLvl,
	},
	Groups = {
		['0:0'] = NoAdminLvl,
	}
}
---
local Bans = {}
---
local Commands = {
	-- Mod --
	{
		Names = {'mod','moderator'},
		Level = AdminLvl,
		Function = function(Chatted,Arguements)
			local Names = Arguements[1]
			-- Check --
			if Names then
				local Plrs = GetPlrs(Chatted,Names)
				-- For Statement --
				for Number,Plr in pairs(Plrs) do
					SetAdminLvl(Plr,ModLvl)
				end
			end
		end,
	},
	-- Admin --
	{
		Names = {'admin','administrator'},
		Level = SuperAdminLvl,
		Function = function(Chatted,Arguements)
			local Names = Arguements[1]
			-- Check --
			if Names then
				local Plrs = GetPlrs(Chatted,Names)
				-- For Statement --
				for Number,Plr in pairs(Plrs) do
					SetAdminLvl(Plr,AdminLvl)
				end
			end
		end,
	},
	-- SuperAdmin --
	{
		Names = {'superAdmin','superadministrator'},
		Level = OwnerLvl,
		Function = function(Chatted,Arguements)
			local Names = Arguements[1]
			-- Check --
			if Names then
				local Plrs = GetPlrs(Chatted,Names)
				-- For Statement --
				for Number,Plr in pairs(Plrs) do
					SetAdminLvl(Plr,SuperAdminLvl)
				end
			end
		end,
	},
	-- Owner --
	{
		Names = {'owner'},
		Level = CreatorLvl,
		Function = function(Chatted,Arguements)
			local Names = Arguements[1]
			-- Check --
			if Names then
				local Plrs = GetPlrs(Chatted,Names)
				-- For Statement --
				for Number,Plr in pairs(Plrs) do
					SetAdminLvl(Plr,OwnerLvl)
				end
			end
		end,
	},
	-- UnAdmin --
	{
		Names = {'unadmin'},
		Level = AdminLvl,
		Function = function(Chatted,Arguements)
			local Names = Arguements[1]
			local Lvl = GetAdmins(Chatted)
			-- Check --
			if Names then
				local Plrs = GetPlrs(Chatted,Names)
				-- For Statement --
				for Number,Plr in pairs(Plrs) do
					if GetAdmins(Plr) < Lvl then
						UnadminPlr(Plr)
					end
				end
			end
		end,
	},
	-- Kick --
	{
		Names = {'kick'},
		Level = AdminLvl,
		Function = function(Chatted,Arguements)
			local Names = Arguements[1]
			local Message = Arguements[2] and Arguements[2][1] or 'Kicked From Server'
			local Lvl = GetAdmins(Chatted)
			-- Check --
			if Names then
				local Plrs = GetPlrs(Chatted,Names)
				-- For Statement --
				for Number,Plr in pairs(Plrs) do
					if GetAdmins(Plr) < Lvl then
						Plr:Kick(Message)
					end
				end
			end
		end,
	},
	-- Ban --
	{
		Names = {'ban'},
		Level = SuperAdminLvl,
		Function = function(Chatted,Arguements)
			local Names = Arguements[1]
			local Message = Arguements[2] and Arguements[2][1] or 'Banned From Server'
			local Lvl = GetAdmins(Chatted)
			-- Check --
			if Names then
				local Plrs = GetPlrs(Chatted,Names)
				-- For Statement --
				for Number,Plr in pairs(Plrs) do
					if GetAdmins(Plr) < Lvl then
						Bans[tostring(Plr.UserId)] = Plr.Name
						Plr:Kick(Message)
					end
				end
			end
		end,
	},
	-- UnBan --
	{
		Names = {'unban'},
		Level = SuperAdminLvl,
		Function = function(Chatted,Arguements)
			local Names = Arguements[1]
			-- Check x2 --
			if Names then
				if Names[1] == 'all' then
					table.clear(Bans)
				else
					for Number,Name in pairs(Names) do
						local FullName,Id = FirstMatch(Bans,Name)
						-- Check --
						if Id then
							Bans[Id] = nil
						end
					end
				end
			end
		end
	},
	-- Server Lock --
	{
		Names = {'slock','serverlock'},
		Level = SuperAdminLvl,
		Function = function()
			ServerLocked = true
		end,
	},
	-- UnServer Lock --
	{
		Names = {'unslock','unserverlock'},
		Level = SuperAdminLvl,
		Function = function()
			ServerLocked = false
		end,
	},
	-- Heading --
	{
		Names = {'h'},
		Level = ModLvl,
		Function = function(Chatted,Arguements,Message)
			-- Check --
			if Message then
				local FilteredMsg = FilterMsg(Message,Chatted)
				Module:FireAllClients('Event','h',Chatted,FilteredMsg)
			end
		end,
	},
	-- Team --
	{
		Names = {'team'},
		Level = ModLvl,
		Function = function(Chatted,Arguements)
			local Names = Arguements[1]
			local Team = nil
			-- Check --
			if Arguements[2] and Arguements[2][1] then
				Team = FirstMatch(Teams:GetChildren(),Arguements[2][1])
			end
			-- Check --
			if Names and Team then
				local Plrs = GetPlrs(Chatted,Names)
				-- For Statement --
				for Number,Plr in pairs(Plrs) do
					Plr.Team = Team
				end
			end
		end,
	},
	-- Teleport V1 --
	{
		Names = {'tp','teleport'},
		Level = ModLvl,
		Function = function(Chatted,Arguements)
			local Names = Arguements[1]
			local Target = Arguements[2] and FirstMatch(Players:GetPlayers(),Arguements[2][1]) or Chatted
			-- Check --
			if Names and Target then
				local Plrs = GetPlrs(Chatted,Names)
				-- For Statement --
				for Number,Plr in pairs(Plrs) do
					Teleport(Plr,Target)
				end
			end
		end,
	},
	-- Teleport V2 --
	{
		Names = {'to'},
		Level = ModLvl,
		Function = function(Chatted,Arguements)
			local Target = Arguements[1] and FirstMatch(Players:GetPlayers(),Arguements[1][1])
			-- Check --
			if Target then
				Teleport(Chatted,Target)
			end
		end,
	},
	-- Teleport V3 --
	{
		Names = {'bring'},
		Level = ModLvl,
		Function = function(Chatted,Arguements)
			local Names = Arguements[1]
			local Plrs = GetPlrs(Chatted,Names)
			-- For Statement --
			for Number,Plr in pairs(Plrs) do
				Teleport(Plr,Chatted)
			end
		end,
	},
	-- Respawn --
	{
		Names = {'respawn','re'},
		Level = ModLvl,
		Function = function(Chatted,Arguements)
			local Names = Arguements[1]
			local Plrs = GetPlrs(Chatted,Names)
			-- For Statement --
			for Number,Plr in pairs(Plrs) do
				Plr:LoadCharacter()
			end
		end,
	},
	-- Refresh --
	{
		Names = {'ref','refresh'},
		Level = ModLvl,
		Function = function(Chatted,Arguements)
			local Names = Arguements[1]
			local Plrs = GetPlrs(Chatted,Names)
			-- For Statement --
			for Number,Plr in pairs(Plrs) do
				local OldCFrame = Plr.Character and Plr.Character:FindFirstChild('Torso') and Plr.Character.Torso.CFrame
				Plr:LoadCharacter()
				-- Check --
				if OldCFrame then
					local Torso = Plr.Character:FindFirstChild('Torso')
					Torso.CFrame = OldCFrame
				end
			end
		end,
	},
}
----

-- Functions --
function FirstMatch(Group,Search)
	local Key = nil
	local Match = nil
	-- For Statement --
	for Number,Child in pairs(Group) do
		local Name = typeof(Child) == 'Instance' and Child.Name or Child
		-- Check --
		if string.match(string.lower(Name),'^' .. Search) then
			Key = Number
			Match = Child
			break
		end
	end
	---
	return Match,Key
end
---
function GetPlrs(Chatted,Names)
	local Plrs
	-- Check --
	if Names then
		local AllPlrs = Players:GetPlayers()
		Plrs = {}
		Plrs = #Names == 1 and Names[1] == 'all' and AllPlrs or {}
		-- Check --
		if Names[1] == 'all' then
			local Number = table.find(AllPlrs,Chatted)
			-- Check --
			if Number then
				table.remove(AllPlrs,Number)
			end
			Plrs = AllPlrs
		else
			local function AddTeam(Team)
				-- For Statement --
				for _,Plr in pairs(Team:GetPlayers()) do
					-- Check --
					if not table.find(Plrs,Plr) then
						table.insert(Plrs,Plr)
					end
				end
			end
			---
			for _,Name in pairs(Names) do
				-- Check --
				if Name == 'me' and not table.find(Plrs,Chatted) then
					table.insert(Plrs,Chatted)
				elseif string.sub(Name,1,5) == 'team-' then
					local Team = FirstMatch(Teams:GetChildren(),string.sub(Name,6))
					AddTeam(Team)
				elseif string.sub(Name,1,1) == '%' then
					local Team = FirstMatch(Teams:GetChildren(),string.sub(Name,2))
					AddTeam(Team)
				else
					local Plr = FirstMatch(AllPlrs,Name)
					-- Check --
					if not table.find(Plrs,Plr) then
						table.insert(Plrs,Plr)
					end
				end
			end
		end
	else
		Plrs = {Chatted}
	end
	---
	return Plrs
end
---
function GetAdmins(Plr)
	local Lvl = Admins.Plrs[tostring(Plr.UserId)] or (RunService:IsStudio() and CreatorLvl) or NoAdminLvl
	-- Check --
	for Number,Grp in pairs(Admins.Groups) do
		local Table = string.split(Number,':')
		local Group = tonumber(Table[1])
		local Rank = tonumber(Table[2])
		-- Check --
		if Plr:GetRankInGroup(Group) >= Rank then
			Lvl = math.max(Lvl,Grp)
		end
	end
end
---
function SetAdminLvl(Plr,Lvl)
	local CurrentLvl = GetAdmins(Plr)
	-- Check --
	if Lvl > CurrentLvl then
		Admins.Plrs[tostring(Plr.UserId)] = Lvl
	end
end
---
function UnadminPlr(Plr)
	table.remove(Admins.Plrs,tostring(Plr.UserId))
end
---
function Teleport(Plr1,Plr2)
	local Char1 = Plr1.Character and Plr1.Character:FindFirstChild('Torso')
	local Char2 = Plr2.Character and Plr2.Character:FindFirstChild('Torso')
	Char1.CFrame = Char2.CFrame * CFrame.new(0,0,-5)
end
---
function FilterMsg(Message,Plr)
	local FilterString = ''
	local Result
	local Success,ErrorMsg = pcall(function()
		Result = TxtService:FilterStringAsync(Message,Plr.UserId)
	end)
	-- Check --
	if Result then
		local Success,ErrorMsg = pcall(function()
			FilterString = Result:GetNonChatStringForBroadcastAsync()
		end)
	end
	---
	return FilterString
end
---
function ParseString(Message)
	Message = string.lower(Message)
	-- Check --
	if string.sub(Message,1,1) == string.lower(Prefix) then
		Message = string.sub(Message,2)
		local Arguements = string.split(Message,Seperator)
		local Command = Arguements[1]
		table.remove(Arguements,1)
		-- For Statement --
		for Number,Arg in pairs(Arguements) do
			Arg[Number] = string.split(Arg,ArguementSeperator)
		end
		local MsgNoCommand = string.sub(Message,string.len(Command) + 1)
		---
		return Command,Arguements,MsgNoCommand
	end
end
----

-- Init --
function Module:OnJoin(Plr)
	-- Check --
	if Bans[tostring(Plr.UserId)] then
		Plr:Kick('Banned From Server')
	elseif ServerLocked and GetAdmins(Plr) == 0 then
		Plr:Kick('Server Is Locked')
	end
	-- On Chatted --
	Plr.Chatted:Connect(function(Message)
		local Command,Arguements,MsgNoCommand = ParseString(Message)
		local Lvl = GetAdmins(Plr)
		-- For Statement --
		for Number,Table in pairs(Commands) do
			-- Check x2 --
			if table.find(Table.Names,Command) then
				if Lvl >= Table.Level then
					coroutine.wrap(Table.Function)(Plr,Arguements,MsgNoCommand)
				end
				---
				break
			end
		end
	end)
end
----
return Module

Nil means theres no value for one of the variables. You can’t compare a non value with a value.

You can print out/or do a watch both of the variables that you’re using on that line, and check which one is nil. Then start investigating why.

1 Like

Just to confirm, does the rest of the code run without any issues? I believe the ‘Lvl’ variable could be nil, because the function you are calling (GetAdmins) does not return anything, you are just changing the Lvl variable that was created within that function.

When I try do something like :refresh me it gives me a complete different error with the ParseString function

I fixed the error. I simply forgot to return the Lvl. I gotta look back at my code before I post these forums :sob:

1 Like

But now I get a error in the Parse Function

Arg[Number] = string.split(Arg,ArguementSeperator)

With the error "Trying to index string with number

NVM IM A DUMMY I WAS CALLING THE WRONG ARGUEMENT [char 2.0]

I was calling Arg instead of Arguements [char2.0]

I believe the solution should go to my post as I have stated the exact reasoning for the issue you have just mentioned in the post I am replying to.

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