Block doesn't align in the plot

Hi, I’m making a grid placement system but it doesn’t align with my plot, image:
and here is my code that I’m using for the grid:

mouse.roundWithGrid = function(ins,p)
	local size2 = ins.Size
	local grid = 3
	local x = math.round(p.X/grid)*grid
	local z = math.round(p.Z/grid)*grid

mouse.GetPosition = function(b)
	local mouseLocation = userInputService:GetMouseLocation()

	local unitRay = workspaceCamera:ViewportPointToRay(mouseLocation.X,mouseLocation.Y);

	local params =;

	params.FilterDescendantsInstances = {player.Character,(b and b)};

	params.FilterType = Enum.RaycastFilterType.Blacklist

	local raycastResult = workspace:Raycast(unitRay.Origin,unitRay.Direction*placementDistance,params);

	if (raycastResult) then
		return (raycastResult.Position +,b.Size.Y/2,0));
		return (unitRay.Origin+unitRay.Direction*placementDistance) +,b.Size.Y/2,0)

I’m using a texture for the grid on the plot. Thanks for reading, and help is appreciated :smiley:

Firstly, I don’t see anywhere you using the roundWithGrid function. I’m assuming there is some code that utilizes it.

Secondly, you are rounding the Vector3 position to the nearest space that’s a multiple of 3, make sure your plot’s CFrame is in a space that’s a multiple of 3 I assume that’s the problem.

Lastly, off topic but

this is unnecessary and also doesn’t make sense, because if the raycast fails it will place block at mouse position * placement distance.

How would I CFrame the plot to a space that’s a multiple of 3?

Assuming your plot size is a multiple of 3, assuming a block is 3 studs on each axis, and assuming each tile is 3 studs on each axis; when you position your plot set the Position to something that is a multiple of 3, and everything should work.

The plot stays at its place and I never move it, also, when I am not play-testing, I can move some blocks that are 3 studs on both X and Z axis, it works perfectly. It just doesn’t work in the game, only in edit-mode.

Tell me do you want the blocks to be able to be placed anywhere or have it locked to a 3x3 grid?

1 Like

It should be locked at 3x3 grid

Can’t this just be fixed by changing the grid texture offset or adding a constant to align the the box?

Your part should still be locked to the grid it’s just has an offset.

As I mentioned when I move the blocks in studio with snap to grid tool open it works but it just doesn’t work in play test mode

Yes, because they are using different sets of code. Just add an offset constant or adjust the texture mapping of the grid texture.

1 Like

Fixed it! Thanks for suggesting that!