What i want to do is have every part created snap to a grid of 2 studs for one, intergers only. Players themselves click on any spot to place a part, and the script snaps the part afterward. I know that i need to use the modulo operator for that, but it doesn't seem to help much.
I am able to snap the grid to intergers, but only to a grid of intergers. Here's my last out of many attempts with comments added:
workspace.ChildAdded:connect(function(child)
print("New child added to Workspace")
if child:IsA("Part") then
print("Snapping child to grid")
print("Original position: " .. child.Position.X .. " " .. child.Position.Y .. " " .. child.Position.Z)
if child.Position.X > 0 then --If X is positive then...
if child.Position.X % 2 ~= 0 then child.Position = Vector3.new(math.ceil(child.Position.X),child.Position.Y,child.Position.Z) end --Snap the part to an interger
if child.Position.X % 2 ~= 0 then child.Position = Vector3.new(math.ceil(child.Position.X),child.Position.Y,child.Position.Z) end --Not divisible afterwards? Snap again.
else --If it's negative then...
if child.Position.X % -2 ~= 0 then child.Position = Vector3.new(math.floor(child.Position.X),child.Position.Y,child.Position.Z) end
if child.Position.X % -2 ~= 0 then child.Position = Vector3.new(math.floor(child.Position.X),child.Position.Y,child.Position.Z) end
end --If Z is negative then...
--Ignore the lines about Y
if child.Position.Y % 1 ~= 0 then child.Position = Vector3.new(child.Position.X,math.floor(child.Position.Y),child.Position.Z) end
if child.Position.Y == 0 then child.Position = Vector3.new(child.Position.X,1,child.Position.Z) end
if child.Position.Z > 0 then
if child.Position.Z % 2 ~= 0 then child.Position = Vector3.new(child.Position.X,child.Position.Y,math.ceil(child.Position.Z)) end
if child.Position.Z % 2 ~= 0 then child.Position = Vector3.new(child.Position.X,child.Position.Y,math.ceil(child.Position.Z)) end
else
if child.Position.Z % -2 ~= 0 then child.Position = Vector3.new(child.Position.X,child.Position.Y,math.floor(child.Position.Z)) end
if child.Position.Z % -2 ~= 0 then child.Position = Vector3.new(child.Position.X,child.Position.Y,math.floor(child.Position.Z)) end
end
child.Position = Vector3.new(child.Position.X,child.Position.Y + 0.5,child.Position.Z)
print("New position: " .. child.Position.X .. " " .. child.Position.Y .. " " .. child.Position.Z)
else
print("New child isn't a part - probably a player character")
end
end)

2 comments
Does the job perfectly!
Be sure to up-vote! :)