I have a simple script where a model moves to the mouse position and when you click it places. My problem is I can't get the mouse to snap to a grid. Here is my movement script:

local Player = game.Players.LocalPlayer
local Mouse = Player:GetMouse()
local Part = workspace.Movement.PrimaryPart

Mouse.Move:Connect(function()
	local PosX = Mouse.Hit.X 
	local PosY = 11.1
	local PosZ = Mouse.Hit.Z
		
	Part.Parent:MoveTo(Vector3.new(PosX, PosY, PosZ))
end)
		
Mouse.Button1Down:Connect(function()
	local ClonedPart = Part.Parent:Clone()
	ClonedPart.Parent = workspace.Clones
	ClonedPart.PrimaryPart.Position = Part.Position
end)

I have tried a couple things to achieve my goal. 1. I have tried to add values to the Mouse position like this:

local PosX = Mouse.Hit.X + 0.5 -- My thoughts on this was that it would add enough movement that it would snap to a grid

It didn't work. I also tried it when I moved the model:

Part.Parent:MoveTo(Vector3.new(PosX + 0.5, PosY, PosZ + 0.5))
-- I don't want to snap the Y to grid

What I have:

  1. Movement
  2. Placement What I don't have:
  3. Snapping the players mouse to a grid.

Thanks to who ever helps me!

1 comment

0

I solved this one myself