How to make a complex grid system?

Hi everyone. I was curious on how I would achieve a grid system where it goes by special increments however, when it nears another object, it automatically snaps onto that object.

can you tell in more depth i dont understand what you mean

robloxapp-20220318-0811533.wmv (513.2 KB)

Sorry for the bad quality. Roblox recorder sucks

are you trying to make the part snap to the wall?

do you see how when i drag it on the top the tall box it does not snap correctly on the surface, I want it to match up evenly along the edges

hmm you can do it by getting the corners of the part then find the closest corner to the Mouse.hit.Position then what you can do is snap to it. you can find closest corner using CFrame! heres example

local corner1 = part.CFrame*CFrame.new(part.Size.X/2,part.Size.Y/2,part.Size.Z/2)

by saying “part”, you mean the block im trying to snap onto?

yes thats what i mean by that also for edges u can use the same formula but just edit it a bit

So it actually put the center of the block on the corner but not the entire thing. How would I make it fit the entire block?

so what u can do is add the part of the size divided by 2 or just copy paste this

local offset = Vector3.new(block.Size.X/2,block.Size.Y/2,block.Size.Z/2)

where block is the part you are moving (this only snaps for corners but i guess u can find for edges as well… right?)