Problem with Structure dragging

I made a structure placement system that is works fine… almost
theres 1 issue that i don’t know what to do with it in the video as u can see i cannot place
side of the wall because scripts defects as it will be inside of the wall

robloxapp-20250221-0241059.wmv (3.8 MB)

local RunService = game:GetService("RunService")
local Players = game:GetService("Players")
local ReplicatedStorage = game:GetService("ReplicatedStorage")

local LocalInput = require(script.Parent.Parent.LocalInput)
local LocalPlayer = Players.LocalPlayer
local Mouse = LocalPlayer:GetMouse()

local Model = ReplicatedStorage:WaitForChild("Sellables").Structures.Part.Model

local gridSize = 0.5 

--------------------------[[ Functions ]]--------------------------

function PrepareModel()
	local NewModel = Model:Clone()
	NewModel.Parent = workspace

	local Highlight = Instance.new("Highlight", NewModel)
	Highlight.Adornee = NewModel
	Highlight.Name = "StructureHighlight"

	for _, part in ipairs(NewModel:GetChildren()) do
		if part:IsA("Part") then
			part.CanCollide = false
			part.CanTouch = false
			part.CanQuery = false
		end
	end

	return NewModel
end

function ConvertToGridSize(mousePosition, HeightSize)
	local newX = math.round(mousePosition.X / gridSize) * gridSize
	local newZ = math.round(mousePosition.Z / gridSize) * gridSize
	local newY = math.round(mousePosition.Y / gridSize) * gridSize
	local newCFrame = CFrame.new(newX, newY + (HeightSize / 2), newZ)
	return newCFrame
end

function IsPositionValid(model, newCFrame)
	if not model.PrimaryPart then return false end

	local primaryPart = model.PrimaryPart
	local size = primaryPart.Size * 0.98 
		
	local region = Region3.new(newCFrame.Position - size / 2, newCFrame.Position + size / 2)

	local overlapParams = OverlapParams.new()
	overlapParams.FilterType = Enum.RaycastFilterType.Exclude
	overlapParams.FilterDescendantsInstances = {Players, model}

	local parts = game.Workspace:FindPartsInRegion3(region, overlapParams)

	return #parts == 0
end

function MoveStructure()
	local NewModel = PrepareModel()
	local modelHeight = NewModel.PrimaryPart.Size.Y 

	while true do
		local mousePosition = Mouse.Hit.Position
		local NewCFrame = ConvertToGridSize(mousePosition, modelHeight)

		if IsPositionValid(NewModel, NewCFrame) then
			NewModel:SetPrimaryPartCFrame(NewCFrame)
			NewModel.StructureHighlight.FillColor = Color3.fromRGB(0, 255, 0)
		else
			NewModel.StructureHighlight.FillColor = Color3.fromRGB(255, 0, 0)
		end

		RunService.RenderStepped:Wait()
	end
end

--------------------------[[ Inputs ]]--------------------------

LocalInput.moveStructure(MoveStructure)

Please help!

It looks like you can only place on top surfaces. Is that what you want or do you also want it to be able to place the edge against a wall off the ground?

Yes i can place in top surfaces also i wanna place in side surfaces without part going to inside of it