I need help with a grid placement system script

I need help trying to create a grid placement system but i have an issue because for some odd reason it snaps wrongly when the part that im snapping on’s position changes.

local Player = game.Players.LocalPlayer
local Mouse = Player:GetMouse()
local Camera = game.Workspace.CurrentCamera
local Grid = game.Workspace.Grid
local Structure = game.Workspace.Structure
local Marker = Structure.Marker
local MosX
local MosY 
local MosZ 

local Grid_Size = 2
local Round = .5

local Floor = math.floor
local Vec3 = Vector3.new

function Move_It(Coordinate, Number)
	return ( Floor( Coordinate / Grid_Size + Round ) * Grid_Size ) + Number
end

function Details()
	MosX = Mouse.Hit.X
	MosY = Mouse.Hit.Y
	MosZ = Mouse.Hit.Z
end

Mouse.Move:Connect(function()
	Details()
	local ray = Ray.new(
			Camera.CFrame.Position, 
			(Mouse.Hit.p - Camera.CFrame.Position).unit * 10
		)
		
	local Hit, Position = game.Workspace:FindPartOnRayWithIgnoreList(ray, Structure:GetChildren())
	
	if Hit == Grid then
		
	end
	if Mouse.Target == Grid then
        Marker.Position = Vec3(Move_It(MosX,	Grid.Position.X), MosY + .1, Move_It(MosZ, Grid.Position.Z))
	end
end)

What is the issue?
I know it has something to do with these lines
return ( Floor( Coordinate / Grid_Size + Round ) * Grid_Size ) + Number
and
Vec3(Move_It(MosX, Grid.Position.X), MosY + .1, Move_It(MosZ, Grid.Position.Z))

1 Like

The ) + Number is probably the problem.

Yea, remove the +Number at the end because the offset of the grid doesn’t matter if you already have the mouse position.