I'm trying to make a punch system that does 5 damage per hit. But for some reason it does way more than 5 damage. I know it has something to do with debounces but I already did add a debounce. I know I'm not very good with scripting. Please help, thanks much.
local UIS = game:GetService("UserInputService") local attacking = false llocal function leftPunch() --Animation local leftPunch = script.LeftPunch local leftPunchTrack = humanoid:LoadAnimation(leftPunch) local leftFist = character:WaitForChild("Left Arm") if not LPcooldown then LPcooldown = true attacking = true leftPunchTrack:Play() wait(2) LPcooldown = false end --Damage leftFist.Touched:Connect(function(hit) local humanoid = hit.Parent:FindFirstChildWhichIsA("Humanoid") if humanoid and attacking then humanoid:TakeDamage(5) wait() --debounce attacking = false end end) end
You need to make sure you define that attacking is false before the damage
like this:
leftFist.Touched:Connect(function(hit) local humanoid = hit.Parent:FindFirstChildWhichIsA("Humanoid") if humanoid and attacking then attacking = false -- defines false before damage so it then won't attack. humanoid:TakeDamage(5) wait() -- add debounce here end end)