You can write your topic however you want, but you need to answer these questions:
What do you want to achieve? Trying to make the health regain work!
**What is the issue? it keeps saying attempt to compare number and boolean on line 19.
– Gradually regenerates the Humanoid’s Health over time.
local REGEN_RATE = 1/100 – Regenerate this fraction of MaxHealth per second.
local REGEN_STEP = 0.1 – Wait this long between each regeneration step.
local Debounce = false
local Character = script.Parent
local Humanoid = Character:WaitForChild’Humanoid’
local currentHealth = Humanoid.Health
Humanoid.HealthChanged:Connect(function(health)
local change = math.abs(currentHealth - health)
currentHealth = health
if not currentHealth > health then
if not Debounce then
Debounce = true
wait(5)
Debounce = false
end
end
end)
while true do
while Humanoid.Health < Humanoid.MaxHealth and Debounce == false do
local dt = wait(REGEN_STEP)
local dh = dtREGEN_RATEHumanoid.MaxHealth
Humanoid.Health = math.min(Humanoid.Health + dh, Humanoid.MaxHealth)
end
Humanoid.HealthChanged:Wait()
end
What solutions have you tried so far? Try to fix it but still errors.
It should work by default, if not then you broke something, and can easily be fixed by opening a new baseplate, testing it, and looking in the health script inside your character, that’s the script ROBLOX uses, so it’s pretty reliable.
Health regenerates by default. You’ve messed something up if it doesn’t. As I said, if you can’t figure out the problem just use a new baseplate, it’ll work there.
The correct code is:
-- 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 < 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