I am currently experiencing an issue within Roblox Studio. When I try to run Player:GetRankInGroup() or Player:IsInGroup() or Player:GetRoleInGroup() it sometimes errors and prints “error: Player not in datamodel”. This usually happens when I run one of those functions after the player left the game.
It’s weird because I haven’t been experiencing it in all of my games, maybe I’ve been enabling something on accident?
local Players = game:GetService("Players")
Players.PlayerAdded:Connect(function(Player)
if Player:GetRankInGroup(000000) >= 255 then
print(Player.Name.." is the owner of the group!")
end
end)
If you need to do something with the player when they leave related to those functions, fetch the values when they join and store it in a variable, and then use those variables in your code when they are leaving. Like this:
local Players = game:GetService("Players")
Players.PlayerAdded:Connect(function(player)
local rank = player:GetRankInGroup(idhere)
-- add more variables as needed
-- I find using AncestryChanged is better in some edge cases than PlayerRemoving from my experience
player.AncestryChanged:Connect(function(_, parent)
if parent ~= nil then return end
--code that does something with the variables above when they leave the game
print(rank)
end)
end)