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

Why won't this zombie damage cool down script work?

Asked by 3 years ago
Edited 3 years ago

Its almost as if the wait(2) is invisible. I posted the same question yesterday and got things about debounces but none of the solutions worked. Please help. I'm not that knowledgeable, but my hypothesis is that it is waiting wait(2), but it is constantly searching for hum so the code is running constantly and dealing damage constantly. My code:


local rarm = script.Parent:FindFirstChild("RightUpperArm") local larm = script.Parent:FindFirstChild("LeftUpperArm") function dmg(hit) if hit.Parent ~= nil then local hum = hit.Parent:findFirstChild("Humanoid") while hum ~= nil do print("phase1") hum.Health = hum.Health -10 print("phase2") wait (2) if hum ~= true then break end end end end rarm.Touched:connect(dmg) larm.Touched:connect(dmg)
0
Are you using a wait on line 7? Because its constantly checking wether the humanoid is not equal to nil and so it wont move to the next part of the script. Make sure you add a wait below line 7. JesseSong 3916 — 3y

2 answers

Log in to vote
0
Answered by 3 years ago

Like what @Jediplocoon did except you didn't properly type out FindFirstChild.

local rarm = script.Parent:FindFirstChild("RightUpperArm")
local larm = script.Parent:FindFirstChild("LeftUpperArm")
canDmg = true;

function dmg(hit)
    if hit.Parent ~= nil then
        local hum = hit.Parent:FindFirstChild("Humanoid")
        while hum ~= nil do
            print("phase1")
            if canDmg then
                hum.Health = hum.Health -10
                canDmg = false;
                wait(2)
                canDmg = true;
            end
            print("phase2")
            if hum ~= true then
            break

            end 
        end
    end
end


rarm.Touched:connect(dmg)
larm.Touched:connect(dmg)

Fairly simple.

0
Deprication doesnt really, matter it's just that in the near future roblox might not be supporting that. So therefore that may not be his problem. JesseSong 3916 — 3y
0
No problemo lol Cynical_Innovation 595 — 3y
0
Wait, one second I was saying no problem to plocoon, and now jesse is here. lol wut Cynical_Innovation 595 — 3y
0
I seriously love you man. we have been stressing over this for so long. I want you to know how special you are to our tiny team and I. Thank you. BayernLucario25TWO 12 — 3y
0
Wow, never had someone be so thankful lol. No problem! Cynical_Innovation 595 — 3y
Ad
Log in to vote
0
Answered by 3 years ago

I haven't coded using Lua in a while, but I'm fairly sure you are using the debounce incorrectly, it might look like this:

local rarm = script.Parent:FindFirstChild("RightUpperArm")
local larm = script.Parent:FindFirstChild("LeftUpperArm")
canDmg = true;

function dmg(hit)
    if hit.Parent ~= nil then
        local hum = hit.Parent:findFirstChild("Humanoid")
        while hum ~= nil do
            print("phase1")
            if canDmg then
                hum.Health = hum.Health -10
                canDmg = false;
                wait(2)
                canDmg = true;
            end
            print("phase2")
            if hum ~= true then
            break

            end 
        end
    end
end


rarm.Touched:connect(dmg)
larm.Touched:connect(dmg)
0
You don't need a semi colon for this case, semi colons are useful for separating tables etc. JesseSong 3916 — 3y

Answer this question