How to add a grid snap in my part dragging system

so i have a part dragging code and i want to add grid system so it snaps in a grid where the grid increment is determined by a textbox but im very bad at math and i dont know how to make a grid snap system here is the current code where it doesnt have grid snapping

mouse.Move:Connect(function()
	if part and drag == true then
		local position = {x = ms.Hit.X;y = ms.Hit.Y;z = ms.Hit.Z;};
	    part.Position = Vector3.new(position.x,position.y + part.Size.Y/2,position.z)
	end
end)

im not sure, but i think you can change this

to this

part.Position = Vector3.new(position.x*4,(position.y + part.Size.Y/2)*4,position.z*4)

with 4 being the studs you want it to snap to

robloxapp-20210620-1707236.wmv (419.5 KB)

its so broken now after following you

oh lol im sorry, as i said im not sure, and btw maybe try this:

part.Position = Vector3.new(position.x/4,(position.y + part.Size.Y/2)/4,position.z/4)

(still not sure)

actually i dont think its gonna work, imma try to redo this script in roblox studio brb

this made my part go missing lol

1 Like

nvm im dumb and cant do it lol, sorry

Try searching here on the devforums, it’s been covered quite a bit I think

1 Like

Like this one, I really found it interesting:

2 Likes

thx never knew that post existed cuz i searched up grid dragging system in devforum that might be the reason i didnt get that post

2 Likes