#healing script

16 messages · Page 1 of 1 (latest)

willow fox
#

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 statsFolder = Character:WaitForChild("Stats")
local Humanoid = Character:WaitForChild'Humanoid'

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

while true do
    while Humanoid.Health < Humanoid.MaxHealth and statsFolder.inCombat.Value == false 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```
#

it still heals when inCombat value is true

midnight socket
#

what is the problem?

sand epoch
#

try this: -- 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 statsFolder = Character:WaitForChild("Stats")
local Humanoid = Character:WaitForChild'Humanoid'


while true do
if Humanoid.Health < Humanoid.MaxHealth and statsFolder.inCombat.Value == false then
local dt = wait(REGEN_STEP)
local dh = dtREGEN_RATEHumanoid.MaxHealth
Humanoid.Health = math.min(Humanoid.Health + dh, Humanoid.MaxHealth)
end
Humanoid.HealthChanged:Wait()
end

willow fox
sleek forumBOT
#

studio** You are now Level 4! **studio

sand epoch
#

I don't know

#

Why

#

Not

sinful mantle
#

Found the issue: It keeps running without properly checking incombat value each iteration.
Fixed code: ```lua
-- 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 statsFolder = Character:WaitForChild("Stats")
local Humanoid = Character:WaitForChild("Humanoid")


while true do
while Humanoid.Health < Humanoid.MaxHealth do
if statsFolder.inCombat.Value then
break
end

    local dt = wait(REGEN_STEP)
    local dh = dt * REGEN_RATE * Humanoid.MaxHealth
    Humanoid.Health = math.min(Humanoid.Health + dh, Humanoid.MaxHealth)
end

local healthChangedConnection = Humanoid:GetPropertyChangedSignal("Health"):Connect(function() end)
local inCombatChangedConnection = statsFolder.inCombat.Changed:Connect(function() end)

wait()

healthChangedConnection:Disconnect()
inCombatChangedConnection:Disconnect()

end

sleek forumBOT
#

studio** You are now Level 1! **studio

sinful mantle
#

wellp

#

try using the script in a different place, maybe some other script is fucking it up

willow fox
#

👍🏿