Sometimes it doesn't detect the humanoid

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)

Ohhh I understand it. Thank you so much for the help.

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