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?
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!