Script gets stuck on loop, why?

Repeat gets stuck on the wait() still even though the player respawned after resetting, but the script ignores the players health going back to default 100.

until game:GetService("Players").LocalPlayer.Character.Humanoid.Health ~= 0

Is this a local script? Or server script?

This script is for a local script.

You would need to put the script in the StaterCharacterScripts folder not the StarterPlayerScripts folder

This is not the issue I am having though.

Where is the script located?


A server script clones it to players backpacks.

Then at this point the localscript will parent itself to nil.

Try this and look at what it prints out:

game:GetService("Players").LocalPlayer.Character.Humanoid.Health ~= 0

Okay, well, if this code is independent (Nothing else is above or below it) then you should make sure the Character Exits by using:

local playersService = game:GetService(“Players”)
local localPlayer = playersService.LocalPlayer
local characterEnsure = localPlayer.Character or localPlayer.CharacterAdded:Wait()
--// characterEnsure will be the event if it hasn’t been added yet, but once it is, it turns to the Character, I used to think it remained but it’s safe to use. You don’t need to add a wait, either, as it used :Wait() so it yields until it’s fired.

Also, don’t forget about task.wait(), it’s technically a better method as it resumes 2x quicker then a normal wait(). You can use it like this:

local IamAwesome = true
while IamAwesome == true do
print(“I am amazing!”)
1 Like

you must put the LocalScript in the StarterCharacterScripts folder, that would’ve working.

I replaced it with this, and now it works fine as intended?

1 Like
local players = game:GetService("Players")
local player = players.LocalPlayer
local character = player.Character or player.CharacterAdded:Wait()
local humanoid = character:WaitForChild("Humanoid")

until humanoid.Health == 0

print("You have died!")

Couple of issues, “~=” is the operator for not equal to (you may have intended to use it), the real reason the script didn’t work is because you hadn’t waited for stuff to properly replicate to the client yet before attempting to reference/index/access them.