GetPartBoundsInBox keeps damaging npc

Hey.

i am making a sword hitbox in this script until i was testing and i got a problem… the npc keeps damaging
i don’t know what to do, i will appreciate if you help me. Thanks

Script:

local Remote = script.Parent.RemoteEvent
local cooldowns = {}

Remote.OnServerEvent:Connect(function(player, alertsend)
	if alertsend == "Attack" then
		if cooldowns[player] then return end
		cooldowns[player] = true
		script.Parent.Handle["sword slash"]:Play()
		script.Parent.Handle.Trail.Enabled = true

		local Hitbox = Instance.new("Part")
		Hitbox.Size = Vector3.new(8,8,8)
		Hitbox.Transparency = 0.9
		Hitbox.Position = player.Character.Tool.Handle.Position
		Hitbox.CanCollide = false
		Hitbox.Anchored = true
		Hitbox.Color = Color3.new(0.690196, 0.0352941, 0.0352941)
		Hitbox.Parent = workspace
		
		local overlamps = OverlapParams.new()
		local hits = workspace:GetPartBoundsInBox(CFrame.new(Hitbox.Position), Hitbox.Size)
		
		for i,v in pairs(hits) do
			if v.Parent then
				local char = v.Parent
				local humanoid = char:FindFirstChild("Humanoid")
				if humanoid and not v:IsDescendantOf(player.Character) then
					humanoid:TakeDamage(10)
					Hitbox:Destroy()
				end
			end
			task.wait(0.500)
			cooldowns[player] = false
			if hits then
				Hitbox:Destroy()
			end
		end
	end
end)

Would you want to use my hitbox resource that I’ve made? it’s using overlap params as well.

1 Like

If not then just use table to help you with the cooldown.