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

9 comments

0

Can you post the scripts here for us to look at?

0

sure, my bad

0

One sec, let me fix that

0

I do the "While true do" on the Heal because it doesn't register the humanoid all the time

0

Just to put this out there, both work for their separate functions. However when they try to work with each other the issue occurs

0

Uh... You mean that when you heal and it does damage it does damage to the value before the heal, like it is erasing the heal?

0

because i think it might be due to the fact you are using a localscript for the heal script.

0

I apologize for not getting back to you earlier

0

How would you go about doing the local script in the damage brick?