UserId index nil issue

I am making chat commands for my game that only staff can use but I cannot get the staff check to work

local Staff = require(game:GetService("ServerScriptService"):WaitForChild("StaffList"))

local StaffCmds = {
	"/kick";
	"/ban";
	"/unban";
	"/tp";
	"/tphere";
	
}

local function checkPlayer(UserId)
	
	for _, StaffId in pairs(Staff) do
		
		if UserId == StaffId then
			
			return true
			
		end
		
	end
	
	return false
	
end

local function findPlayer(name)
	
	local NameLength = string.len(name)
	
	for _, player in pairs(game.Players:GetPlayers()) do
		
		if string.sub(player.Name,1,NameLength):lower() == name then
			
			return player
			
		end
		
	end
	
	return nil
	
end

game.Players.PlayerAdded:Connect(function(player)
	
	player.Chatted:Connect(function(msg, sender)
		
		msg = string.lower(msg)
		
		local splitString = msg:split(" ")
		
		local cmdName = splitString[1]
		
		if table.find(StaffCmds, cmdName) then
			
			local isStaff = checkPlayer(sender.UserId)
			
			if isStaff == true then
				
				if cmdName == "/kick" then

					local PlrToKickName = splitString[2]

					local Reason = splitString[3]

					if PlrToKickName then

						local PlrToKick = findPlayer(PlrToKickName)

						if PlrToKick then
							
							print(PlrToKick)

							PlrToKick:Kick(Reason)

						end

					end

				end
				
			end
			
		end
		
	end)
	
end)

In Player.Chatted, the recipient parameter (you named it sender) is the player that the message was whispered to. However, this is deprecated.
Instead of indexing sender.UserId, use player.UserId.

does it say on the documentation that it is deprecated?

sender is probably nil because plr.Chatted dosent use a second argument, use player.UserId to check if they are staff in your chat script

It does, however in your case you don’t want to check if the player that the message was whispered to is a staff member, but instead if the player themselves is a staff member. That is why you need to use player.UserId in your case.

https://developer.roblox.com/en-us/api-reference/event/Player/Chatted