Grid Snapping Help

Imma keep this short.

This is a grid

I implemented it so the player can hover over a specific part of that grid and the grid selection model will snap into it

It works with a 1 x 1 selection but this happens in a 3 x 3 selection

Why does it over snap like that despite the raycast being cast on the correct part, considering that the primary part of the grid selection model is in the middle? If you need the code I can send it, but as of now I need a good system on how to implement this. Anyone has ideas?

How does the grid snapping work?

for every mouse movement. a raycast is made with the mouse as its origin point. It’s then checked if the instance that is being hit is a part with an attribute called “Interactable”. If it’s true, the grid selection model pivots to the part position that got hit. I don’t understand why it’s not working properly when the grid selection goes to a 3 x 3 considering that it works flawlessly when it’s only 1 part. (The primary part of the grid selection model is the middle part of the box)

Can you show the script where the raycast is done?

local raycastresult = workspace:Raycast(mouse.Hit.Position + Vector3.new(0,150,0), Vector3.new(0,-275,0))

Here is where it snaps to the grid:
gridSelection:PivotTo(CFrame.new(raycastresult.Instance.Position + Vector3.new(0,raycastresult.Instance.Size.Y/2,0)))