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)
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.
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)