While wait() loop stops on player death

This loop:

while wait() do
	local alt =  0.28 * hrp.Position.Y - workspace.Baseplate.Position.Y
	altmeter.Altitude.Text = math.floor(alt).." M"
end

Works perfectly fine, but when you die and respawn, it doesn’t work. How do I make it so that it continues even when you respawn?

Where is the script? show a print of your explorer

It is in a LocalScript, does that have something to do with it?

I mean, where the script is in the explorer, if it’s on Character Scripts, Player Gui or another place

1 Like

Is it erroring? It might be because, if it’s in starterplayer scripts, the humanoidrootpart is unable to found while the player is dead, so it can’t get the altitude?

It doesn’t error, but still stops when dying. I have it in StarterPlayerScripts so that could be the problem.

If you’re relying on that script being in “StarterPlayerScripts”, make sure you’re updating the “hrp” variable whenever a new character is added.

Like this:

Player.CharacterAdded:Connect(function(newCharacter)
hrp = newCharacter:WaitForChild("HumanoidRootPart",10) 
end)

After resetting and respawning, it now gives an error relating to the TextLabel that it uses.

Try toggling this off
image

So that’s what that does? I never knew, thanks!

1 Like

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.