So I have 2 bricks, both have the same script, but one does damage and the other heals
When I touch the damage brick I lose the 10 hp I tell it to take away And when I touch the heal brick I heal my health back
The issue is that after healing I go and touch the damage brick and it takes away way more then 10 health
What I believe the issue is, is that when the damage code goes into affect it saves the value that
the health was at after it damaged it
Then when the heal code adds more health, the damage code reset the health back to where it saved it and starts damaging it from there
Damage Script(Normal Script):
local debounce = true script.Parent.Touched:connect(function(hit) if debounce then debounce = false local ply = hit.Parent local h = ply:FindFirstChild("Humanoid") local dmg = 10 if h then h.Health = h.Health - dmg wait(1) debounce = true end end end)
Heal Script(Local Script):
local debounce = true local functionstarted = false print 'script?' while true do wait() if functionstarted == false then script.Parent.Touched:connect(function(hit) functionstarted = true print'function started' if debounce == true then print'debounce activated' debounce = false local heal = game.Players.LocalPlayer.PlayerGui. Classes.Healer.Abilities.HealCircle. HealthPerSecond.Value local CharHe = game.Players.LocalPlayer. Character:WaitForChild("Humanoid") if hit.Parent == game.Players.LocalPlayer.Character then print'humanoid found' if CharHe.Health < (CharHe.MaxHealth/100 * 97) then print'healing began' CharHe.Health = CharHe.Health + (CharHe.MaxHealth/100 * heal) wait(1) functionstarted = false debounce = true end end if not hit.Parent then print'humanoid missing' functionstarted = false end end end) end end