I've been trying to make a grid system for my build mode and when you move your mouse it never aligns the the 2 by 2 grid as a texture on the plot. What I see is that the x and z are fighting making the block move diagonal. No one has the answer and I've been asking for days!!! Please Help!!!!!!

BTW the function is on line 59-----------------------------------------------------------------

local RunService = game:GetService("RunService")
local UIS = game:GetService("UserInputService")

local Player = game.Players.LocalPlayer
local Char = Player.Character or Player.CharacterAdded:Wait()
local Mouse = Player:GetMouse()
local Camera = workspace.CurrentCamera
local PlaceObject = game.ReplicatedStorage.BuildEvents.PlaceObject

local GivenPlot = game.ReplicatedStorage.BuildEvents.GivenPlot
local PlaceObject = game.ReplicatedStorage.BuildEvents.PlaceObject

local GridSize = 2

local posX 
local posY 
local posZ
local posXround
local posZround
local YPos = Vector3.new(0, 75, 0)
local Rot = 0

local Object
local Plot
local PlotO
local ButtonObject = script.Parent.ScrollingFrame.Soil.ImageButton

local CanStart = true
IsPlacing = nil
local CanPlace = nil

GivenPlot.OnClientEvent:Connect(function(plt)
	Plot = plt.Name
	PlotO = plt.Orientation
	PlotX = PlotO.X
	PlotY = PlotO.Y
	PlotZ = PlotO.Z
end)
local function Placement()
	if IsPlacing and CanPlace then
		PlaceObject:FireServer(posX, posY, posZ, Rot, Object.Name, PlotX, PlotY, PlotZ)
		
		IsPlacing = false
		CanPlace = false
		CanStart = true
		
		Object:Destroy()
	end
end
local function TopDownView()
	if IsPlacing then
		local playerPos = Char:FindFirstChild("HumanoidRootPart").Position
		local cameraPos = playerPos + YPos
		
		Camera.CFrame = CFrame.new(cameraPos, playerPos)
	end
end

local function Snap()
	posXround = Mouse.Hit.X
	posX = math.floor(posXround / GridSize + 0.5)*2
	posZround = Mouse.Hit.Z
	posZ = math.floor(posZround / GridSize + 0.5)*2
	posY = Mouse.Hit.Y
	Object.PrimaryPart.Orientation = (Vector3.new(PlotX, PlotY, PlotZ))
end

local function Movement()
	if IsPlacing and CanPlace and not CanStart and Mouse.Target and Mouse.Target.Name == Plot then
		Mouse.TargetFilter = Object
		
		Snap()
		
		Object:SetPrimaryPartCFrame(Object.PrimaryPart.CFrame:Lerp(CFrame.new(posX, posY, posZ) * CFrame.Angles(0, math.rad(Rot), 0), 0.2))
		Object.PrimaryPart.Orientation = (Vector3.new(PlotX, PlotY, PlotZ))
	else
		return Mouse.Hit.p
	end
end

local function StartPlacementSoil()
	if CanStart then
		Object = game:GetService("ReplicatedStorage").Soil:Clone()
		Object.Parent = workspace
		Mouse.Move:Connect(Movement)
		IsPlacing = true
		CanPlace = true
		CanStart = false
		
		Mouse.Move:Connect(Movement)
	end
end

local function StartPlacement(obj)
	if CanStart then
		Object = game.ReplicatedStorage:FindFirstChild(obj):Clone()
		Object.Parent = workspace
		
		IsPlacing = true
		CanPlace = true
		CanStart = false
	end
end

local function Rotation(input, GPE)
	if IsPlacing and CanPlace and not CanStart and input.KeyCode == Enum.KeyCode.R then
		Rot = Rot + 90
		
		Object:SetPrimaryPartCFrame(Object.PrimaryPart.CFrame * CFrame.Angles(0, math.rad(Rot), 0))
	end
end

Mouse.Button1Down:Connect(Placement)
ButtonObject.MouseButton1Click:Connect(function()
	StartPlacement("Soil")
end)
RunService:BindToRenderStep("Input", Enum.RenderPriority.Input.Value, Movement)
UIS.InputBegan:Connect(Rotation)