Health Script not changing Rate of Health

  1. What do you want to achieve?
    I need to change the health rate of someone, the change is already done outside of the health script.
  2. What is the issue?
    The modifier changes, however the rate does not.
  3. What solutions have you tried so far?
    I tried using task.spawn() to insert 2 things to change the rate of healing while using the while true do loop of the original Roblox Health Script.

ORIGINAL CODE

-- Gradually regenerates the Humanoid's Health over time.
local Character = script.Parent
local Humanoid = Character:WaitForChild'Humanoid'

--------------------------------------------------------------------------------


local REGEN_RATE = 1/100 -- Regenerate this fraction of MaxHealth per second.
local REGEN_STEP = 0 -- Wait this long between each regeneration step.

--------------------------------------------------------------------------------

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()
	REGEN_STEP = Character.RegenRate.Value
	task.wait()
	print(REGEN_STEP)
end

task.spawn() CODE

-- Gradually regenerates the Humanoid's Health over time.
local Character = script.Parent
local Humanoid = Character:WaitForChild'Humanoid'

--------------------------------------------------------------------------------


local REGEN_RATE = 1/100 -- Regenerate this fraction of MaxHealth per second.
local REGEN_STEP = 0 -- Wait this long between each regeneration step.

--------------------------------------------------------------------------------

task.spawn(function()
	while true do
		if Humanoid.Health < Humanoid.MaxHealth then
			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
end)

task.spawn(function()
	while true do
		REGEN_STEP = Character.RegenRate.Value
	end
end)

I don’t know what exactly is going wrong with this. In theory it should change the time in between each healing to make it faster when RegenRate is lower.

Using this script it just makes the regeneration rate 0 after some time, even though the numbervalue RegenRate is either 0.1 or 1.

Remember that this is still here : /

– Gradually regenerates the Humanoid’s Health over time.
–local Character = script.Parent
–local Humanoid = Character:WaitForChild(‘Humanoid’) – Adjusted previously "Character:WaitForchild’Humanoid’ "


–local REGEN_RATE = 1/100 – Regenerate this fraction of MaxHealth per second.
–local REGEN_STEP = 0 – Wait this long between each regeneration step.


–while true do
– while Humanoid.Health < Humanoid.MaxHealth do
– local dt = wait(REGEN_STEP)
– local dh = REGEN_RATE*Humanoid.MaxHealth – This resulted in 0 so I fixed it I think
– Humanoid.Health = math.min(Humanoid.Health + dh, Humanoid.MaxHealth)
– end
– Humanoid.HealthChanged:Wait()
– REGEN_STEP = Character.RegenRate.Value – Not sure if this is a numberValue but I changed it
– task.wait()
– print(REGEN_STEP)
–end

local Players = game:GetService(“Players”)
local REGEN_RATE = 1/100 – Regenerate this fraction of MaxHealth per second.
local REGEN_STEP = 0 – Wait this long between each regeneration step.

Players.PlayerAdded:Connect(function(player)
player.CharacterAdded:Connect(function(chr)
local Humanoid = chr: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()
		REGEN_STEP = 1
		task.wait()
		print(REGEN_STEP)
	end

end)

end)

I made some changes to the code it works, but I don’t know if it’s the original health regen or the code. Try this.

I fixed it myself, it was declaring and using REGEN_STEP and REGEN_RATE that actually made it not work (basically I replaced each REGEN_STEP and REGEN_RATE with a call to the Character.RegenWhatever value.), but thanks.

1 Like

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