Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
0

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

Asked by 6 years ago
Edited 6 years ago
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

Log in to vote
0
Answered by 6 years ago

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!

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 XX_Scripta 11 — 6y
0
That works too. Please accept the answer if it helped you :) ThatPreston 354 — 6y
Ad

Answer this question