Making a fortnite building system

What I am trying to do is to get the parts to build over eachother, I keep getting this error on this area of line of code.
Line of code:

	-- only clamp we're fully covered (margin of error included)
			local area = modelSize.x * modelSize.z
			local clamp = (sum < area - 0.1)

			local lpos = cf:pointToObjectSpace(position);
			local size2 = (size - Vector2.new(modelSize.x, modelSize.z))/2
			local x = clamp and math.clamp(lpos.x, -size2.x, size2.x) or lpos.x
			local y = clamp and math.clamp(lpos.y, -size2.y, size2.y) or lpos.y	
[ ReplicatedStorage.MultiPlacement:60: max must be greater than min])

--In this case, since its a sample of what the code is, the line this error begins in is local x =- clamp and math.clamp.

If anyone could help would be appreciated

2 Likes

Imagine size2.x and size.y being negative. What do you do when this happens?

math.clamp(20, -(-100), -100) -- also equals math.clamp(20, 100, -100)

So what should I add to this code? What should I specifically change?

Try math.abs to eliminate negative values.

math.clamp(lpos.x, -math.abs(size2.x), math.abs(size2.x))

-- OR

local size2 = math.abs((size - Vector2.new(modelSize.x, modelSize.z))/2)
3 Likes