Hitboxes lagging?

Hello people, I am making a combat game and find that when I create lots of hitboxes, it makes the game slow. (It only lasts for a few seconds after the move, but it’s still a pretty bad problem.)

If you don’t know what I mean:

Here’s my code for anyone that wants it, if that’s is the problem.

local Hitbox = Assets:WaitForChild("Objects").Hitbox:Clone()
	Hitbox.Parent = BarrageFolder
	Hitbox.CFrame = HumRP.CFrame * CFrame.new(0,0,-4.5)
	Hitbox.Size *= 1.2
	if Hitbox.Parent == workspace then
	local HWeld = Instance.new("WeldConstraint",Hitbox)
	HWeld.Part0 = Hitbox
	HWeld.Part1 = HumRP

	local Connection
	local ignorelist = {}
	Connection = Hitbox.Touched:Connect(function(hitPart)
		if hitPart:IsA("BasePart") then
			local Enemy = hitPart.Parent or hitPart.Parent.Parent
			local EHumanoid = Enemy:FindFirstChild("Humanoid")
			local EHumRP = Enemy:FindFirstChild("HumanoidRootPart")
			if Enemy ~= Character then
				if EHumanoid and EHumRP then
					if EHumanoid.Health ~= 0 then
						-- damage, disconnect connection etc.

I know that hitboxes are sometimes problematic and inconsistent, but I’ve tried it quite a few times before and they worked as intended.

1 Like

you could try generating 1 hitbox at the start of the attack, and only making new ones when the enemies position changes outside of the box (2-5 studs maybe), and then deleting the hitbox after the attack has finished


Nevermind, I fixed it by using Magnitude. But thanks for your reply!

1 Like