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