So I'm making a game inspired by Create Your Own Security Base, my stamper works fine, it has a 4x4 grid. But the problem is, the Y position doesn't work as it is meant for, this is what I use for my position
local grid = 4 function snap() local position = mouse.Hit.p return CFrame.new( position.X - position.X % grid, position.Y - position.Y % grid, position.Z - position.Z % grid ) end
It also doesn't position the Y position correct Image for what it does
I suggest you don't use % for this. If your part is at position 3.9, on a 4x4 grid it would snap to 0, when it's closer to 4. A really easy to sort stuff like this is just to use math.floor
local Floor = math.floor local function RoundToNearest(ToRound, Increment) return Floor(ToRound/Increment + 0.5)*Increment end RoundToNearest(1.2, 0.5) - Round 1.2 to the nearest 0.5 increment RoundToNearest(5.4, 4) - Round 5.4 to the nearest 4 increment.
So for your code,
local Floor = math.floor local function RoundToNearest(ToRound, Increment) return Floor(ToRound/Increment + 0.5)*Increment end local grid = 4 function snap() local position = mouse.Hit.p return CFrame.new( RoundToNearest(position.X, grid), RoundToNearest(position.Y, grid), RoundToNearest(position.Z, grid), ) end