Tool dealing more damage than it's supposed to

i have this hammer tool and there is a hitbox and when the tool is activated the hitbox deals damage to the humanoid it is touching

when i activate it it works as it’s supposed to but when the player touches it, it’s dealing more damage than it’s supposed to

i tried adding a debounce to it, but it didn’t work as well

hitbox.Touched:Connect(function(hit)
			local db = false
			local humanoid = hit.Parent:FindFirstChild("Humanoid")
			if db == false then 
				db = true
				humanoid:TakeDamage(15)
				handle.Hit:Play()
				task.wait(cooldown)
				db = false
			end
		end)

fyi, i might not see your post cause i’m supposed to be sleeping lol and i have probably gotten in trouble by now

3 Likes

Put the db before the hitbox.touched

local db = false
hitbox.Touched:Connect(function(hit)
			
	local humanoid = hit.Parent:FindFirstChild("Humanoid")
	if db == false then 
		db = true
		humanoid:TakeDamage(15)
		handle.Hit:Play()
		task.wait(cooldown)
		db = false
	end
end)
2 Likes

Also, don’t call it debounce and especially don’t call it db, those aren’t good variable names. You’ll be better off naming it isOnCooldown or something along those lines.

3 Likes
local isOnCooldown = true
		hitbox.Touched:Connect(function(hit)
			local humanoid = hit.Parent:FindFirstChild("Humanoid")
			if db == true then 
				db = false
				humanoid:TakeDamage(15)
				handle.Hit:Play()
				task.wait(cooldown)
				db = true
			end
		end)

i did that and it broke the hammer

1 Like

you named the variable “isOnCooldown” but still used “db”

dont worry i changed it earlier

i just woke up lol

so is it working now? if so, mark one of the posts as a solution

it isnt it wont deal damage after listening to one of the responses

local isOnCooldown = true
		hitbox.Touched:Connect(function(hit)
			local humanoid = hit.Parent:FindFirstChild("Humanoid")
			if isOnCooldown == true then 
				isOnCooldown = false
				humanoid:TakeDamage(15)
				handle.Hit:Play()
				task.wait(cooldown)
				isOnCooldown = true
			end
		end)
1 Like

i have it set to 15 damage, but it dealt 90 damage

Can you you post the whole script

local tool = script.Parent
local handle = tool.Handle
local model = tool.Model
local hitbox = model.Hitbox

local animation = script.Animation

local db = true
local cooldown = 3

for i, Parts in pairs(model:GetChildren()) do
	if Parts:IsA("BasePart") then
		local weld = Instance.new("WeldConstraint")
		weld.Part0 = Parts
		weld.Part1 = handle
		weld.Parent = Parts
	end
end

tool.Activated:Connect(function()

	if db == true then
		db = false

		local character = tool.Parent
		local humanoid = character:WaitForChild("Humanoid")

		local animationTrack = humanoid:LoadAnimation(animation)
		animationTrack:Play()

		local isOnCooldown = false
		hitbox.Touched:Connect(function(hit)
			local humanoid = hit.Parent:FindFirstChild("Humanoid")
			if isOnCooldown == false then 
				isOnCooldown = true
				humanoid:TakeDamage(15)
				handle.Hit:Play()
				task.wait(cooldown)
				isOnCooldown = false
			end
		end)

		task.wait(cooldown)
		db = true
	end
end)

tool.Equipped:Connect(function()
	local sound = tool.Handle.Music

	sound:Play()
	sound.Looped = true

	tool.Unequipped:Connect(function()
		sound:Stop()
	end)
end)
1 Like

Try this


local tool = script.Parent
local handle = tool.Handle
local model = tool.Model
local hitbox = model.Hitbox

local animation = script.Animation

local db = true
local cooldown = 3

for i, Parts in pairs(model:GetChildren()) do
	if Parts:IsA("BasePart") then
		local weld = Instance.new("WeldConstraint")
		weld.Part0 = Parts
		weld.Part1 = handle
		weld.Parent = Parts
	end
end

local db = false 
tool.Activated:Connect(function()



	if not db then
		db = true 
		local character = tool.Parent
		local humanoid = character:WaitForChild("Humanoid")

		local animationTrack = humanoid:LoadAnimation(animation)
		animationTrack:Play()

	
		local poop
		poop = hitbox.Touched:Connect(function(hit)
			local humanoid = hit.Parent:FindFirstChild("Humanoid")
				
			if humanoid then
				poop:Disconnect() 
				humanoid:TakeDamage(15)
				handle.Hit:Play()
			end
				
		
		end)

		wait(cooldown)
		poop:Disconnect() 
		db = false 
		
	end 
	
end)

tool.Equipped:Connect(function()
	local sound = tool.Handle.Music

	sound:Play()
	sound.Looped = true

	tool.Unequipped:Connect(function()
		sound:Stop()
	end)
end)



1 Like

Oh, thank you very much for helping me out!

2 Likes

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.