print(math.floor(Mouse.Hit.X / GridSize) * GridSize) print(math.floor(Mouse.Hit.X))
Let's say that mouse X is 50 and gridsize is 2. That means that the first one will do 50/2 = 25 * 2 = 50 Bottom one will be 50.
Same answer, yet, when I made a snap building system, it gives different results.
FULL SCRIPT:
local Player = game.Players.LocalPlayer local Mouse = Player:GetMouse() local PosX local PosY local PosZ local Model = game.ReplicatedStorage.Crate:Clone() Model.Parent = workspace local GridSize = 5 local function snap() PosX = math.floor(Mouse.Hit.X / GridSize) * GridSize PosY = Model.PrimaryPart.Position.Y PosZ = math.floor(Mouse.Hit.Z / GridSize) * GridSize end local function Movement() --Mouse.TargetFilter = Model snap() Model:SetPrimaryPartCFrame(CFrame.new(PosX, PosY, PosZ)) end Mouse.Move:Connect(Movement)