How do i make a block placement system with Grid support

For the past 2 years i have been doing on and off project that i don’t finish or the code is too complicated for me.

But the most interesting project i want to try make is a block placement system with grid support. I have tried to watch YT tutorials but some aren’t what i want.

Is there anyone that could help me with this?

For block:
1 - you need know, where you pointing on block, no, not that you meaned rn. You should move block to CFrame(0,0,0), and keep on it that point.
Offset = Target.CFrame:Inverse() * CFrame.new(Position) * Target.CFrame.Rotation
point at that moment shouldn’t have rotation, bc block haven’t rotation too.
2 - you need offset your selected prop (which you trying to place), by X, Y, or Z Size /

if math.round((TargetCFrame:Inverse() * CFrame.new(Position)).Position.X * 10000) / 10000 >= Target.Size.X / 2 then
	OffsetSize = Vector3.new(Part.Size.X / 2, 0, 0)
elseif math.round((TargetCFrame:Inverse() * CFrame.new(Position)).Position.X * 10000) / 10000 <= -Target.Size.X / 2 then
	OffsetSize = Vector3.new(-Part.Size.X / 2, 0, 0)
elseif math.round((TargetCFrame:Inverse() * CFrame.new(Position)).Position.Y * 10000) / 10000 >= Target.Size.Y / 2 then
	OffsetSize = Vector3.new(0, Part.Size.Y / 2, 0)
--and 3 other situations - make them by your hand.

3 - Now, apply OffsetSize to Offset:
Offset = Offset * CFrame.new(OffsetSize)
4 - Now grid part. (Sadly IDK how explain this) we here just rounding our Offset:

local Pos = Offset.Position
Offset = CFrame.new(math.round(Pos.X / MoveSnap) * MoveSnap, math.round(Pos.Y / MoveSnap) * MoveSnap, math.round(Pos.Z / MoveSnap) * MoveSnap)

5 - Now set part back to original:
Part.CFrame = Target.CFrame * Offset
(Target = part, on which you pointing your mouse)
(Position = mouse.Hit.position)