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.
What is the issue?
The modifier changes, however the rate does not.
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.
â 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.