Question about while player do

If you have playeradded and then u have a while player do

if the player leaves does the code keep running?

playeradded:Connect(func(plr)
while plr do

end
end)

cant find much help for downhill rush cause the servers keep crashing and idk why

1 Like

Yeah the following is incorrect, just ignore it

Eventually player should point to nil which would break the loop.

2 Likes

so the argument is a reference to the player then and not an object idk

It points to the player object. When a player leaves, their player object will get destroyed.

1 Like

This isn’t true, the object will stick around even after they leave. You can do while plr.Parent do instead.

2 Likes

no this loop will not stop when the player leaves because it is not truly destroyed

you should instead do

while game:GetService("Players"):FindFirstChild(player.Name) do
--some code
end
1 Like

Ahh. I was wrong. It is worth noting however, that the part you quoted is actually not incorrect. Destroying an object does the following:

Sets the Instance.Parent property to nil, locks the Instance.Parent property, disconnects all connections, and calls Destroy on all children - Instance:Destroy

So the player is technically destroyed. However you likely meant it in context with my other post.

This is where I was wrong. You are still referencing player despite the fact properties were locked and it was parented to nil. For some reason my brain just decided that since the object was destroyed it would be nil… That would actually be strange behavior to expect so I’m unsure why I was thinking that at the time of post.

1 Like