Trouble with workspace:GetPartBoundsInBox()

So I have this script that calls a function using :GetPartBoundsInBox() to return the table. I have it check if the table is empty, but I cant figure out why it isn’t returning from the if statement.

params=OverlapParams.new()
params.FilterDescendantsInstances=CloneMachine:GetDescendants()

function checkHitbox()
	return workspace:GetPartBoundsInBox(
		CFrame.new(-222.777,108.299,-894.081),
		Vector3.new(4.72,5.599,4.64),
		params
	)
end

runPrompt.Triggered:Connect(function(player)
	local entranceHitbox=checkHitbox()
	print(entranceHitbox)
	if entranceHitbox=={} then print("THERE IS NOTHING IN THE BOXX") return else
		for i,instance in entranceHitbox do
			print(instance,instance.Parent)
			
		end
	end
end)

Any ideas?

2 Likes

i’d suggest just using a for loop instead of that complicated thing

local box = workspace:GetPartBoundsInBox(cframe, size)
local table = {}

for _,v in box do
   if v.Parent then
   table.insert(table, v.Parent)
   print(table)
   end
end

something might error here because i just woke up

1 Like

Use #entranceHitbox == 0 instead of that.

-- print({} == {}) This will always print false because tables compare to their memory address
-- more like: print(0x7baf203485bc2016 == 0x46d6d40c59da7666)

if #entranceHitbox == 0 then
    print("empty")
    return
end

for i, instance in entranceHitbox do
    print(instance, instance.Parent)
end
2 Likes

Thank you, it woks perfectly now : D

1 Like

I tested this and it also would’ve worked, thanks : D

1 Like

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