'Error: Player not in datamodel' with :IsInGroup() Function

Not sure how this occurs but sometimes with certain players this function will error saying: 'Error: Player not in datamodel’

Here is my code: (Inside a PlayerAdded event and on a Server Side Script)

elseif plr:IsInGroup(0) == true then -- a group id
	-- code here
end

I’ve tried switching some stuff up like doing if plr:IsInGroup() then, instead of == true but no luck. Only happens on some players every now and then tho.

Maybe I should wait for the player or smth? So confused tbh.

Have you put in your group ID in the parenthesis? also you do not need the ‘== true’

yes the group idea is there in my actual code, and yes I don’t need the == true I was testing out random stuff tbh

I assume the error has to do with the function running while or after the player leaves the game. I’m pretty player:IsInGroup can only be used for in-game players.

1 Like

hmm, is your function happening after a player leaves?

It happens when the player joins

Documentation uses this function when players join the game tho.
https://developer.roblox.com/en-us/api-reference/function/Player/IsInGroup

You could try adding a conditional wait to it such as:

if not plr.Parent then
	plr:GetPropertyChangedSignal("Parent"):Wait()
end

If that doesn’t work, a more gritty method would be the following:

local TIMEOUT_THRESHOLD = 5
if not plr.Parent then
	local Timeout = 0 -- Added a timeout just incase player never comes out of nil
	repeat
		Timeout += task.wait()
	until plr.Parent or Timeout >= TIMEOUT_THRESHOLD
end

if plr.Parent then
	-- do stuff here.
	if plr:IsInGroup(0) == true then
		
	end
end

Ahh, add a yielding function to stop the code from trying to run before the player is a descendant of the game

Is the player one of the Roblox dummy accounts? it may be causing the issue because their ids are invalid(negative userIds -1, -2, -3 etc.).

Even if it was it wouldn’t be the cause of the issue, as a “dummy” roblox account is still in the datamodel.

I’ll give this a go, this may be it tbh.

will defo consider this, thank u

thought this would work, but it didn’t