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

Healing script lasts forever and heals too much, what wrong?

Asked by 4 years ago

So i have two problems:

  1. My character is supposed to heal 10 health per second, but instead he heals like 50 health per milisecond.

  2. the healing lasts forever, no matter if i am touching the healing brick or not. the only way to stop it is to die.

heres the script:

function OnTouched (person)
    local i = person.Parent:FindFirstChild("Humanoid")
    if i ~= nil then
        while i ~= nil do
            wait(1)
            i.Health = i.Health + 10
        end
    end
end

script.Parent.Touched:Connect(OnTouched)
0
add a debounce rupertrosse 39 — 4y
0
how exactly? PicoTheRiko 34 — 4y

1 answer

Log in to vote
2
Answered by 4 years ago

add a debounce

local deb = true
local active = true
function OnTouched (person)
    if active = true then
        active = false
        if deb == true then
            deb = false
            local i = person.Parent:FindFirstChild("Humanoid")
            if i ~= nil then          


                i.Health = i.Health + 10

            end
        wait(1)
        deb = true
        end
    end
end

function touchended()
active = true
end

    script.Parent.Touched:Connect(OnTouched)
    script.Parent.TouchEnded:Connect(touchended)

i havent tested this , because im too lazy to , if someone can take over , ... ok

0
you need to walk around the part tho , it sucks , but i dont have enough time to think rupertrosse 39 — 4y
0
if my guess is right plz upvote , if not , ... k rupertrosse 39 — 4y
0
this works! PicoTheRiko 34 — 4y
Ad

Answer this question