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.
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.
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