Describe the bug. Describe what is happening when the bug occurs. Describe what you would normally expect to occur.
I get Player must be a child of Players as an error when using the PlayerAdded event
How often does the bug happen (Everytime/sometimes/rarely)? What are the steps that reproduce the bug? Please list them in very high detail. Provide simple example places that exhibit the bug and provide description of what you believe should be the behavior.
Enough that I see it in my logs about 30 times per day from a game that gets ~4k visits per day.
Where does the bug happen (www, gametest, etc) Is it level-specific? Is it game specific? Please post a link to the place that exhibits the issue.
Live
When did the bug start happening? If we can tie it to a specific release that helps us figure out what we broke.
First seen on 8th Sept
Anything else that you would want to know about the bug if it were your job to find and fix it.
The code used is the following:
function setupPlayer(player)
-- Do stuff
end
game.Players.PlayerAdded:connect(function(player)
setupPlayer(player)
end
Alright so either :GetRoleInGroup is attempting to re-parent or somehow the error gets thrown while the code is running that line (I think I get the latter when testing code that needs to be broken/killed - like an infinite while loop).
I can guarantee that no reparenting of players is done within the script.
There is an infinite loop in a spawn() function, you think that could interrupt the HTTP request for GetRoleInGroup?
Not really. That also still wouldn’t explain the error, I think.
I believe it has something to do with whatever is re-parenting player acting similar to the while loop example and not throwing an error from the correct source.
You’ll probably need to talk to someone who knows this better than me lol
I don’t think this has anything to do with reparenting.
I’m pretty sure GetRoleInGroup is programmed and designed such that you are only supposed to be getting the role of players that are in the game. That’s why it’s a method of Player instead of GroupService, and why it errors if the player is not “in the game”. You’re not allowed to get the role of players that are not in the game, such as players that have left the server.
Try putting something like this before you use GetRoleInGroup:
while player.Parent ~= game.Players do
wait()
end
If that fixes it, then it seems that the bug is either:
PlayerAdded is firing before the player is a child of Players (bug)
or players are removed before your code runs…
by internal Roblox programming (bug)
or by programming in your game, that could, for example, be kicking players before you check their role (your problem that you need to fix)
I’ve just added checks to see if they are a child of Players to stop this appearing but it does seem strange that a player can join a game, trigger PlayerAdded and leave before GetRoleInGroup returns.
Thanks for the help guys @Lilly_S lock please
Maybe they’re lagging out and close Roblox, which still runs for a tiny bit in the background. It completes connection and in the same packet sends the “I left the game” stuff. PlayerAdded fires while the connection is already closed (thus the Player parented to nil)
just a guess. could always scan through the NetworkReplicators and see if the player is actually still connected to see if this is actually the case