Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
0

How do I create a dmg brick without it interfering with my healing brick?

Asked by 4 years ago
Edited 4 years ago

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
0
Can you post the scripts here for us to look at? cmgtotalyawesome 1418 — 4y
0
sure, my bad DylanD319 9 — 4y
0
One sec, let me fix that DylanD319 9 — 4y
0
I do the "While true do" on the Heal because it doesn't register the humanoid all the time DylanD319 9 — 4y
View all comments (5 more)
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 DylanD319 9 — 4y
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? RetroGalacticGamer 331 — 4y
0
because i think it might be due to the fact you are using a localscript for the heal script. RetroGalacticGamer 331 — 4y
0
I apologize for not getting back to you earlier DylanD319 9 — 4y
0
How would you go about doing the local script in the damage brick? DylanD319 9 — 4y

Answer this question