Error: Player:IsInGroup error: Player not in datamodel

I got this error that breaks the whole game, how could I fix the problem?
Skärmklipperror
It’s hard to try to fix the problem because it works like 99% of the time, so I would appreciate all kind of help.

This is where it breaks, if you want more code just ask :slight_smile:

if v:IsInGroup(9340560) == true then
     v.leaderstats[bitname].Value = v.leaderstats[bitname].Value + 5
end

Thank you,
/Xsodar

Could you show your i,v loop? :smile:

Here it is, the whole function.

function module.Winners(reward,bitname,winname)
	runningFunction.Value = "Winners"								
	local playersnowin = 0
	for i,v in pairs(game.Players:GetChildren()) do
		if workspace:FindFirstChild("Minigame") and v:FindFirstChild("RankSystem") and v.RankSystem:FindFirstChild("Current") and v:FindFirstChild("leaderstats") and v.leaderstats:FindFirstChild(bitname) and v.leaderstats:FindFirstChild(winname) and v:FindFirstChild("Playing") and v.Playing.Value == true then
			local vip = v.Passes:FindFirstChild("PlayerHasVIP")
			local passExp = v.Passes:FindFirstChild("PlayerHasXTwoExp")
			local passBits = v.Passes:FindFirstChild("PlayerHasXTwoBits")
			
			if gamefolder.Players.Value <= workspace.Minigame.GameConfig.PlayersToEnd.Value then
				status.Value = ""
				
				if v:IsInGroup(9340560) == true then
					v.leaderstats[bitname].Value = v.leaderstats[bitname].Value + 5
				end
				
				if passExp.Value == true and vip.Value == false then
					v.RankSystem.Current.Value = v.RankSystem.Current.Value + 20
				end
				
				if passBits.Value == true and vip.Value == false then
					v.leaderstats[bitname].Value = v.leaderstats[bitname].Value + 20
				end
				
				if vip.Value == true then
					if vip.Value == true and passBits.Value == true then
					v.leaderstats[bitname].Value = v.leaderstats[bitname].Value + 60 -- Pass BIT
					elseif vip.Value == true and passBits.Value == false then
					v.leaderstats[bitname].Value = v.leaderstats[bitname].Value + 20	
					end
					
					if vip.Value == true and passExp.Value == true then
						v.RankSystem.Current.Value = v.RankSystem.Current.Value + 40 -- Pass EXP
					elseif vip.Value == true and passExp.Value == false then
						v.RankSystem.Current.Value = v.RankSystem.Current.Value + 10	
					end
					
				end
				v.leaderstats[bitname].Value = v.leaderstats[bitname].Value + reward
				v.leaderstats[winname].Value = v.leaderstats[winname].Value + 1              --Normal reward
				v.RankSystem.Current.Value = v.RankSystem.Current.Value + 20
				game.ReplicatedStorage.Remotes.PlayerWins:FireAllClients(v)
			
			else
			status.Value = "No Winner!"		
		end
			
		else
			playersnowin = playersnowin + 1
		end
		if playersnowin == i then
			status.Value = "No Winner!"	
		end
	end
end

May I suggest instead of GetChildren() you instead use GetPlayers()?

Okay I can try that, will this solve this error or is something else you can do to make it even better?

Is gamefolder ever defined? {30ChARRAS}

Try using
for i,v in pairs (game.Players:GetPlayers()) do

GetChildren() returns every object parented inside the player, not the individual Player Instances; if you want to check that a Player is in a specific group, use GetPlayers() method like @ItsNickBoi110 mentioned

Most likely means that the player has left the game lol.
The method returns an error. Meaning the method exists on the player.

Just run an integrity Check by doing the following

if not Player or Player.Parent ~= game.Players then return end
1 Like
local gamefolder = game.ReplicatedStorage.Game

I have this in the beginning of the script so yes.

This will not work as you are not using any type of method once you define game.Players. :wink:

1 Like

Are you still receiving the error even after you changed it to GetPlayers()?

1 Like

My bad I should have caught myself on that I haven’t scripted in a while.

It’s alright, but I would also like to mention GetPlayers() only returns Player instances, so technically there would be no use in using if v:IsA('Player') then.

Yea, true i’m also rlly tired rn just got back from a baseball game. :joy:

This error does not happen all the time so I don’t know, but I did what @AsynchronousMatrix and also did what you suggested. So I think it will work, thanks.

This seems to be a reoccurring issue while using the method IsInGroup(), perhaps file a bug report!

DevForum Searches