Placement System Issue

I’m creating a placement system and it’s taken me ages to get this far, for the most part the objects have been fine however now I’m trying to implement walls that are 5, 15, 0.5 in size are they appear to only rotate 2 directions.

Although my other items rotate all 4 directions as shown below.

There is a TON of code but here’s the rotation

For reference the GRID_UNIT is 5 meaning these tiles are 5 studs large, The Spawner item in the video is a 10x20 hitbox and the walls are 0.5x5

I have tried both my normal rotate and the “Smart Rotate” function and either way the walls rotate 2 directions

-- Handles rotation of the model
local function ROTATE(actionName: string, inputState: Enum.UserInputState, inputObj: InputObject?)
	if not (currentState ~= 4 and currentState ~= 2 and inputState == Enum.UserInputState.Begin) then return end
	if smartRot then
		-- Rotates the model depending on if currentRot is true/false
		if currentRot then rotation += rotationStep; else rotation -= rotationStep end
		print(rotation)
	else
		rotation += rotationStep
	end

	-- Toggles currentRot
	local rotateAmount = round(rotation/90)
	currentRot = rotateAmount%2 == 0 and true or false
	if rotation >= 360 then rotation = 0 end
	if preferSignals then rotated:Fire() end
end

This is the snapping and plot clamping functions I’m using

-- Clamps the x and z positions so they cannot leave the plot
local function bounds(c: CFrame, offsetX: number, offsetZ: number): CFrame
	local pos: CFrame = plot.CFrame
	local xBound: number = (plot.Size.X*0.5) - offsetX
	local zBound: number = (plot.Size.Z*0.5) - offsetZ

	local newX: number = clamp(c.X, -xBound, xBound)
	local newZ: number = clamp(c.Z, -zBound, zBound)

	local newCFrame: CFrame = cframe(newX, 0, newZ)

	return newCFrame
end

-- Returns a rounded cframe to the nearest grid unit
local function snapCFrame(c: CFrame): CFrame
	local offsetX: number = (plot.Size.X % (2*GRID_UNIT))*0.5
	local offsetZ: number = (plot.Size.Z % (2*GRID_UNIT))*0.5
	local newX: number = round(c.X/GRID_UNIT)*GRID_UNIT - offsetX
	local newZ: number = round(c.Z/GRID_UNIT)*GRID_UNIT - offsetZ
	local newCFrame: CFrame = cframe(newX, 0, newZ)

	return newCFrame
end

If there is something else I should post to improve my chances of getting help just ask

Could you show the output of the rotation? I noticed you were printing it

That was just me making sure SmartRotation wasn’t doing something unintended it just prints either 0 or 90 as that’s what SmartRot does is simplify rotation to 2 directions. I tried fixing the walls using both 2 directions and having SmartRot disabled for 4 directions but both had the same result.

I’ve noticed the issue is only affecting items that have an axis that is lower than 5 studs (The grid unit) for example the wall being 0.5 studs thick. As long as the hitbox is 5 studs wide the rotation is perfectly fine but this would not be a valid solution to my walls as then you wouldn’t be able to place another item on the same tile as a wall.

Could you print currentrot before you subtract the rotation (or add), see if it’s nil or false

CurrentRot is a True/False value to do the SmartRot where there is only 2 rotation directions

This is what the issue looks like when snapping an item that has an X or Z that is less than the GRID_UNIT which is 5 studs

However when it’s an item larger than 5 studs on the X and Z the snapping is fine

I think i know that the issue might be, your script may be detecting the wall’s position as being out of the grid and snapping it back with your snapCFrame function