Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
✓ ANSWER ACCEPTED

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

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)

1 comment

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.

2 answers

✓ Accepted answer

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.

5 comments

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.

0

No problemo lol

0

Wait, one second I was saying no problem to plocoon, and now jesse is here. lol wut

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.

0

Wow, never had someone be so thankful lol. No problem!

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)

1 comment

0

You don't need a semi colon for this case, semi colons are useful for separating tables etc.

This discussion is preserved as it was. New answers, comments, and votes are closed.