I have a grid for placing furniture and each grid square is 2 studs by 2 studs how can I make it so when you place it stays in the 2 by 2 grid lines. This is what I have so far:
local Player = game.Players.LocalPlayer
local Mouse = Player:GetMouse()
local mTarget
local Down
function clickObject()
if Player.BuildMode.Value == true and Mouse.Target ~= nil and not game.Workspace.StarterPlot then
mTarget = Mouse.Target
print(mTarget)
Mouse.TargetFilter = mTarget
print(Mouse.TargetFilter)
Down = true
end
end
Mouse.Button1Down:Connect(clickObject)
function mouseMove()
if Down and mTarget then
local posX, posY, posZ = Mouse.Hit.X, Mouse.Hit.Y, Mouse.Hit.Z
posX = posX/2
local function round(posX)
return math.floor(posX + 0.5)
end
posX = posX * 2
posY = posY/2
local function round(posY)
return math.floor(posY + 0.5)
end
posY = posY * 2
posZ = posZ/2
local function round(posZ)
return math.floor(posZ + 0.5)
end
posZ = posZ * 2
mTarget.Position = Vector3.new(posX, posY, posZ)
end
end
Mouse.Move:Connect(mouseMove)
function mouseDown()
Down = false
Mouse.Target = nil
Mouse.TargetFilter = nil
end
Mouse.Button1Up:Connect(mouseDown)

5 comments
How would I round the number through the script?
You can use the function: local function round(n) return math.floor(n + 0.5) end just run the function as round(the number you want to round to nearest whole)
It didn't work I edited the post so here's the script please tell me what is wrong. Thanks
It still doesn't work..... I've searched but still it does not work
If it isn't quite working as intended, try changing the "0.5" to "0" on line 20. example: return math.floor(number + 0). This would fix the problem of the block being half offseted.