How can I make a script that does this: when a player's health goes under 80, It doesn't regen to 100, but 80 instead. If the health is above 80, then it will regen to 100. (You may be able to do to this by changing the 'Health' script inside a player's model).
Thanks
Make sure this is a Server Script, and it's named Health, and it's located inside StarterCharacterScripts.
-- Gradually regenerates the Humanoid's Health over time. local REGEN_RATE = 1/100 -- Regenerate this fraction of MaxHealth per second. local REGEN_STEP = 1 -- Wait this long between each regeneration step. -------------------------------------------------------------------------------- local Character = script.Parent local Humanoid = Character:WaitForChild('Humanoid') -------------------------------------------------------------------------------- while true do while Humanoid.Health < 80 do local dt = wait(REGEN_STEP) local dh = dt*REGEN_RATE * Humanoid.MaxHealth Humanoid.Health = math.min(Humanoid.Health + dh, Humanoid.MaxHealth) end Humanoid.HealthChanged:Wait() end
Upvote / Accept if this helped you. :)
First, you may want to add something to your game like a health regen pad so it doesn't infinitely give health, otherwise they're "godded".
Here's a script that may work if they step on a regen pad:
--Health REGEN PAD --Parent is regen pad local db = false script.Parent.Touched:connect(function(part) if part.Parent and part.Parent:FindFirstChild'Humanoid' and not db then db = true local health = part.Parent.Humanoid.Health if health >= 80 then health = 100 else health = 80 end wait(1) db = false end end)
The db variable is debounce so it doesn't give them too much health by just standing on the pad.