Attempt to index nil with 'GetRankInGroup'

Hey there so I’m making an admin command system and wrote a function that would return if a player is allowed to use a command.

	if commands[command] then
		local rankNeeded = commands[command][1] 
		if rankNeeded < plr:GetRankInGroup(GroupID) or (rankNeeded == Officer and plr:GetRankInGroup(GroupID) == SM) then
			return true
		else
			return false
		end
	else
		MainModule.invalid('function not found')
	end
end

For the past few days, this worked perfectly and I didn’t change any of the code but it throws the error
attempt to index nil with ‘GetRankInGroup’ and I’m pretty sure I defined the player variably correctly.

Command function below

MainModule.bring = function (plr, args, plr2)
	print('Bring ')
	
	print(args)
	
	local character = plr.Character
	
	local plr2Name
	if args[2] ~= nil then
	 plr2Name = (args[2])
	else
      plr2Name = ''
	end
	
	if returnRank(plr, 'bring') then
		if getTarget(plr2Name, plr) then
			print('target found')
			
			local target = getTarget(plr2Name)
			local targetChar =  target.Character or target.CharacterAdded:Wait()
			local mainChar = plr.Character or plr.CharacterAdded:Wait()
			if CompareRank(target, plr) then
			    targetChar.HumanoidRootPart.CFrame = targetChar.HumanoidRootPart.CFrame + (mainChar.HumanoidRootPart.CFrame.LookVector * mainChar.HumanoidRootPart.Position)
				MainModule.logcommand(plr, 'bring')
			end 
		end
	end
end

Server script below (this will fire the functions)

local setting = require(script.Parent.Parent.Modules.Settings)
local prefix = setting.Prefix	
local commands = require(script.Parent.Parent.Modules.Commands)
local Main = require(script.Parent.Parent)

game.Players.PlayerAdded:Connect(function(plr)


	plr.Chatted:Connect(function(msg)
		
		Main.PlrAdded()
		msg = string.lower(msg)
		
		local splitstring = msg:split(' ')
		
		local slashCommand = splitstring[1]
		
		local cmd = slashCommand:split(prefix)
		
		local cmdName = cmd[2]
		
		print(cmd[2])
		
		Main[cmdName](plr, splitstring, nil)
		
		if commands[cmdName] then
            
			Main[cmdName](plr, cmd, nil)
		end

		 
	end)
end)

Help will be appreciated thank you.

can I see the full function that checks if the player can use a command?

This is all correct. But I believe maybe the player was nil, so you indexed nil with :GetRankGroup which wouldn’t work.

function returnRank(plr, command)
	if commands[command] then
		local rankNeeded = commands[command][1] 
		if rankNeeded < plr:GetRankInGroup(GroupID) or (rankNeeded == Officer and plr:GetRankInGroup(GroupID) == SM) then
			return true
		else
			return false
		end
	else
		MainModule.invalid('function not found')
	end
end

plr:GetRankInGroup(GroupID) == SM
What is SM? Is it a var?

I just deleted a line of code that was supposed to check if a player is banned and now it works fine the ending problem was datastores wasn’t enabled and it was messing up the code and I forgot to pass on the ‘player’ paremeter for the code below

Main.PlrAdded()

:confused: Lua is really weird.

SM is the rank in the group required to do Level 5 commands, PS this is for a Military Simulator