I made a build tool for my game, But I tried to moving stud to stud. (When I click some here,I want to part move like to colliding to 4 stud grid.)
Here's Code:
--Intilaze Player's Mouse local playerMouse = game.Players.LocalPlayer:GetMouse() local pos = 0 --Tool Equipped script.Parent.Equipped:Connect(function(build) --Mouse Down Event build.Button1Down:Connect(function() print(playerMouse.hit.p) local cwb = game.Workspace.WoodBlock:Clone() cwb.Parent = game.Workspace cwb.Position = playerMouse.hit.p cwb.CFrame = cwb.CFrame + Vector3.new(0,4,0) end) end)
Well its actually more complicated you would have to use math.floor
im actually attempting something like this myself and ive spent 4 days on it already its part of my game
So the snapping would be like
local Gridsize = 6 Marker.CFrame = CFrame.new((math.floor(mouse.Hit.X / GridSize +.5 ) * GridSize), Grid.Position.Y + .1, (math.floor(mouse.Hit.Z / GridSize ) * GridSize))
In my case i was making a floor for the grid system so i did
Grid.Position.Y + .1