A bug with finding a player happens only in game while working in Roblox Studios

I’m making an arrest command, however, my check where I make sure the player inside of the group is a low enough rank that they aren’t immune to arrests keeps bringing up an error. This error is that I am attempting to index group rank with nil, however the script works fine in Studios until I go to test it in the game itself. What could be causing this? The player I find from the player list works normally in studios but doesn’t seem to print correctly in game which is what I assume is causing the error.

-- local GroupId = 32519780 --REPLACE 1234567 WITH YOUR GROUP ID
local LowestStaffRank = 11 --REPLACE 255 WITH THE MINIMUM RANK ID TO RECEIVE HELP NOTIFICATIONS

game.Players.PlayerAdded:Connect(function(Player)
	Player.Chatted:Connect(function(Message)
		local Words = string.split(Message, " ")
		if Words[1] == "-arrest" then
			local FoundPlayer
			for _,v in pairs(game:GetService("Players"):GetPlayers()) do
				if string.find(v.Name, Words[2]) then --I assumed args[2] would be the part of the name.
					FoundPlayer = v
					print(FoundPlayer)
				end
				if FoundPlayer:GetRankInGroup(32519780) < 11 then
					local MinutesRemaining = FoundPlayer.leaderboard.jailtimer
					if tonumber(Words[3]) <= 5 then
					MinutesRemaining.Value = Words[3]
						FoundPlayer:LoadCharacter()
						print("end script")
					end
				end
			end
		end
	end)
end)
4 Likes