I’m using a block for a hitbox for a weapon. However, sometimes it doesn’t even detect the humanoid and does no damage. Any help?
local cooldown = false
script.Parent.Touched:Connect(function(hit)
if hit.Parent:FindFirstChild("Humanoid") then
if script.Parent.Parent.CanDamage.Value == true then
if cooldown == false then
cooldown = true
hit.Parent.Humanoid.Health -= 25
script.Parent.Parent.Axe.HitSound:Play()
wait(1)
cooldown = false
end
end
end
end)*emphasized text*
You should check if hit.Parent.Parent also finds a humanoid because of hats and gears.
local cooldown = false
script.Parent.Touched:Connect(function(hit)
local humanoid=nil
if hit.Parent:FindFirstChild("Humanoid") then humanoid=hit.Parent:FindFirstChild("Humanoid") end
if humanoid==nil then --humanoid wasnt found in first check so check if hit.Parent.Parent finds it
if hit.Parent.Parent:FindFirstChild("Humanoid") then humanoid=hit.Parent.Parent:FindFirstChild("Humanoid") end
end
if humanoid ~=nil then
if script.Parent.Parent.CanDamage.Value == true then
if cooldown == false then
cooldown = true
humanoid.Health -= 25
script.Parent.Parent.Axe.HitSound:Play()
wait(1)
cooldown = false
end
end
end
end)