workspace:GetPartBoundsInBox() not working

Hi!
I’ve recently tried applying the popular module “ObjectCache” do a script in my game which creates hitboxes.
These hitboxes use workspace:GetPartBoundsInBox() to evaluate if they hit a player or not.
Oddly now, the function just hardly detects anything anymore. Not even the environment when removing the overlapParams.

– Create a template hitboxes - This is used as a template by the objectCache for the code below.

local template = Instance.new("Part")
	template.Size = Vector3.new(1,1,1)
	template.Anchored = true
	template.CanCollide = false
	template.CanQuery = false
	template.Transparency = 1

– The main hitbox code.

local cframe = CFrame.lookAt(enemy.Position + Vector3.new(0,1.2,0), aimPosition)
			cframe += (cframe.LookVector * (maxRange/2))
			local hitboxPart = cache:GetPart(cframe)
			
			hitboxPart.Size = Vector3.new(0.35,0.35, maxRange)

			task.delay(0.25, function()
				cache:ReturnPart(hitboxPart)
			end)

			local overlapParams = OverlapParams.new()
			overlapParams.FilterDescendantsInstances = { imagine things here yea yea }
			overlapParams.FilterType = Enum.RaycastFilterType.Exclude

			local hits = workspace:GetPartBoundsInBox(hitboxPart.CFrame, hitboxPart.Size, overlapParams)
			for _, v : BasePart in hits do
				local player = players:GetPlayerFromCharacter(v.Parent)
				if player then
					playerUtilities.DamagePlayer(player, 5)
				end
			end

As seen in the code, the hitbox should apply 5 damage to the player if they get hit. Though again, the :GetPartBoundsInBox() function doesn’t return anything anymore - Just an enemy table.

Any ideas why?
Help would be greatly appreciated!!

i ran into this problem like 2 weeks ago but i forgot how i fixed it…

Oh… Well that’s unfortunate lol.

Do you think you’d be able to check out the code you’ve written to perhaps identify the fix?
Thank you!

That’d be massively appreciated!

As the function name suggests, “part bounds in box,” it detects the faces that overlap with the other parts:

Returns an array of parts whose bounding boxes overlap a given box.

So, you’re probably trying to get objects within its volume, not its area, so you could use GetPartsInPart:

local cframe = CFrame.lookAt(enemy.Position + Vector3.new(0,1.2,0), aimPosition)
cframe += (cframe.LookVector * (maxRange/2))

local hitboxPart = cache:GetPart(cframe)
hitboxPart.Size = Vector3.new(0.35,0.35, maxRange)
task.delay(0.25, function()
	cache:ReturnPart(hitboxPart)
end)

local overlapParams = OverlapParams.new()
overlapParams.FilterDescendantsInstances = { imagine things here yea yea }
overlapParams.FilterType = Enum.RaycastFilterType.Exclude

local hits = workspace:GetPartsInPart(hitboxPart, overlapParams)
for _, v : BasePart in hits do
	local player = players:GetPlayerFromCharacter(v.Parent)
	if player then
		playerUtilities.DamagePlayer(player, 5)
	end
end

For some reason this doesn’t detect the player either…

I have found a fix. I just had to add a

task.wait()

after the creation of the hitbox part as the overlap checking was apparently to fast.