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
return Vector3.new(x,p.Y,z)
end
mouse.GetPosition = function(b)
local mouseLocation = userInputService:GetMouseLocation()
local unitRay = workspaceCamera:ViewportPointToRay(mouseLocation.X,mouseLocation.Y);
local params = RaycastParams.new();
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 + Vector3.new(0,b.Size.Y/2,0));
else
return (unitRay.Origin+unitRay.Direction*placementDistance) + Vector3.new(0,b.Size.Y/2,0)
end
end

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

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.

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.