How to make grid system move by two studs instead of one stud

local Players = game:GetService("Players")

local Player = Players.LocalPlayer 

local Mouse = Player:GetMouse()

local Button = script.Parent

local ReplicatedStorage = game:GetService("ReplicatedStorage")

local RemoteFolder = ReplicatedStorage:WaitForChild("Remotes")

local EnemyFolder = ReplicatedStorage:WaitForChild("Enemies")

local Remote = RemoteFolder:WaitForChild("Remote1")

local Fire = EnemyFolder:WaitForChild("Fire")

Button.MouseButton1Down:Connect(function(x, y)
	local Clone = Fire:Clone()
	Clone.Parent = workspace
	while true do
		wait()
		local X = Mouse.Hit.Position.X
		local Y = Mouse.Hit.Position.Y
		local Z = Mouse.Hit.Position.Z
		local NX = math.floor(X)
		local NZ = math.floor(Z)
		Mouse.TargetFilter = Clone
		Clone.CFrame = CFrame.new(Mouse.Hit.Position)
		Clone.CFrame = CFrame.new(math.floor(NX/1), 1, math.floor(NZ/1))
	end
end)

This grid system idk how it works but it moves a block one stud at a time, I want it to move by two studs but idk how i would approach that problem. I’m really confused by the formulas and stuff too

2 Likes

You fan try this function:

function snap(x, n) 
    return math.floor(x / n + 0.5) * n
end

-- usage
clone.CFrame = CFrame.new(snap(X, 2), 1, snap(Z, 2)) 
5 Likes