I’m trying to change the health regen amount in my game to 3. I’ve got it figured out but my issue is that when the player’s health reaches 0, the game keeps adding +3 health to player, if that makes sense. My script is down here below if you want to check it and try it out in your game and see the error yourself. Also, I have it placed in the ‘StarterCharacterScripts’ folder:
local player = game.Players.LocalPlayer
local chr = player.Character
script.Parent = chr
local healthScript = chr:WaitForChild("Health")
healthScript:Destroy()
script.Name = "Health"
-- Gradually regenerates the Humanoid's Health over time.
local REGEN_RATE = 3/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 Humanoid.Health > 0 do
while Humanoid.Health < Humanoid.MaxHealth 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
Just grab the health script from your character copy and paste, put into starterCharacterScripts, and change the wait to what ever you want and the fraction to change the amount it changes when it does go up.
There is a script called Health inside the player’s character.
You can remove it and modify this (server-script):
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 < Humanoid.MaxHealth 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
local Players = game:GetService('Players')
local NewHealth = script.Health
Players.PlayerAdded:Connect(function(Player)
Player.CharacterAdded:Connect(function(Character)
local Health = Character:FindFirstChild('Health')
if Health then
Health:Destroy()
NewHealth:Clone().Parent = Character
end
end)
end)