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

How to set a players health to infinite until respawn?

Alright, so basically.

PLAYER TAKES DAMAGE --> IF PLAYER HEALTH BELOW 5 THEN ---> PLAYER HEALTH INFINITE --> PLAYER RESPAWNED? --> RESET HEALTH TO 100

Honestly, I'd show the code I've done, I've tried everything I can think of. It's driving me up the wall, I've never been so annoyed aha. Any help?

2 comments

0

use a spawnpoint and set the force-field to take longer before turning of

0

thank you ,vortex, but i don't think you've grasped my issue

1 answer

✓ Accepted answer

Dude. Seriously. Use a Changed function to check if health has been changed, and then if the health is < 5 then set to infinity. Health resets back to 100 whenever they respawn:

game.Players.PlayerAdded:Connect(function(p)
    p.CharacterAdded:Connect(function(c)
        c:WaitForChild("Humanoid").HealthChanged:Connect(function()
            if (c.Humanoid.Health <= 5) then
                c.Humanoid.MaxHealth = math.huge;
                c.Humanoid.Health = math.huge;
            end
        end)
    end)
end)

Don't bother asking where to put this, I'll leave that up to you. If you researched Events and Signals in the slightest you'd understand what to do.

..honestly, what did you even try? o-o

4 comments

0

Haha, yes, I did trry. I did also use a changed function, but obvs didn't get it. Thank you for your kind help. On checking your script,"c:WaitForChild("Humanoid"):GetPropertyChangedSignal("Health"):Connect", doesn't actually work, I've tried this by putting a print before and after it, the one before it runs, and the one after doesn't (even after me taking damage). Any idea why?

0

Make sure this is in a server script somewhere. I edited to use the HealthChanged which is leagues shorter than what I wrote. Note that the script has to run before the first client joins. Setting the Health property on the Humanoid doesn't work either, you have to take damage via the TakeDamage method of the humanoid.

0

Editted up, when you say it needs to run before the first client joins. I'm probably an idiot for thinking this, but, how do I get the script to run before the client joins?

0

By placing it at the top of your script, or making sure that your script doesn't yield anytime before the connection.

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