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 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!!
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