{} is not equal to {}

I’m trying to make a building system and have a box that shows the position that the object is going to be placed at.
But when I try to detect collisions using Part:GetTouchingParts() I’m having the problem that it says there’s collisions even though the table that the function returns is empty.

Code:

while true do
	part1:PivotTo(CFrame.new(Vector3.new(mouse.Hit.X,mouse.Hit.Y+(part1.Size.Y/2),mouse.Hit.Z)))
	if (part1:GetTouchingParts() == {}) then
		colliding = false
		part1.Color = Color3.fromRGB(0,255,0)
	else
		colliding = true
		part1.Color = Color3.fromRGB(255,0,0)
	end
	print(colliding)
	print(part1:GetTouchingParts())
	wait()
end

output:

true
{}
true 
{}
etc

No different tables will ever evaluate to each other, so even {} == {} will never be true.

Instead, try checking if it’s empty by using the length operator:
image

image

image

1 Like

There is also the way of type(), in case someone was wondering about how to check if something is a table or not.

print(type({}) == type({})) -- true

This however will not account for the quantity or contents of the table.

print(type({1}) == type({"no", 2})) -- true
1 Like

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