Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
✓ ANSWER ACCEPTED

How would I detect if a player is removing with a repeat wait() until?

game.Players.PlayerAdded:connect(function(player)
repeat wait() 
print("0.1")
until player.PlayerRemoving or player.Character.Humanoid.Health <= 10
print("Player has left.")

How would I fix it to do the repeat wait() until the player removes. I am certain I need to make it into a function for the player removing. Something like this

game.Players.PlayerRemoving:Connect(function(player)

end)

But I have no idea how I would do that with the until, can anyone give me some advice?

1 answer

✓ Accepted answer

There's a few ways you could achieve this. With an infinite loop, you can just keep checking until the Player doesn't exist. Essentially, the condition would just be not Player, like this. Keep in mind if this code is in a LocalScript it may be removed before it finishes executing.

repeat
	wait()
until
	not Player

Instead of using an infinite loop, I would use the :Wait() function. Basically, by calling :Wait() on an event, it will wait until this event is fired. You can use this to check if a player leaves like so.

repeat
	game:GetService("Players").PlayerRemoving:Wait()
until
	not Player

Hope this helps. Good luck!

2 comments

0

Thanks what I did was I just put local pla = player.Name (skip down to the until line) until game.Players:FindFirstChild(pla) == nil or player.Character.Humanoid.Health <= 10

0

That works too. Please accept the answer if it helped you :)

This discussion is preserved as it was. New answers, comments, and votes are closed.