How would i make this building system not be able to place if there is another object in the way?

local Mouse = game.Players.LocalPlayer:GetMouse()
local Positiona = nil
local Rot = Vector3.new(0, -90, 0)
local UIS = game:GetService("UserInputService")

UIS.InputBegan:Connect(function(Key)
	if Key.KeyCode == Enum.KeyCode.R then
		Rot += Vector3.new(0, -90, 0)
		
		if script.Parent:FindFirstChild("Ghost") then
			script.Parent.Ghost:Destroy()
		end
		local Ghost = Instance.new("Part", script.Parent)
		Ghost.Name = "Ghost"
		Ghost.CFrame = Positiona
		Ghost.Anchored = true
		Ghost.Size = Vector3.new(3.9, 0.35, 4)
		Ghost.Transparency = 0.8
		Ghost.Color = Color3.new(0, 0, 0)
		Ghost.Rotation = Rot

		local GhostImage = Instance.new("Decal", Ghost)
		GhostImage.Texture = "rbxassetid://13199053500"
		GhostImage.Face = "Top"
	end
end)

script.Parent.Activated:Connect(function()
	
	script.Parent.place:FireServer(Positiona, Rot)
	
end)

Mouse.Move:Connect(function()
	local GridSize = 4
	local X = math.floor((Mouse.Hit.X + GridSize / 2) / GridSize) * GridSize
	local Y = math.ceil((Mouse.Hit.Y + GridSize / 4 ) / GridSize) * GridSize - 3.85
	local Z = math.floor((Mouse.Hit.Z + GridSize / 2) / GridSize) * GridSize
	Positiona = CFrame.new(X, Y, Z)
	
	if script.Parent:FindFirstChild("Ghost") then
		script.Parent.Ghost:Destroy()
	end
	local Ghost = Instance.new("Part", script.Parent)
	Ghost.Name = "Ghost"
	Ghost.CFrame = Positiona
	Ghost.Anchored = true
	Ghost.Size = Vector3.new(3.9, 0.35, 4)
	Ghost.Transparency = 0.8
	Ghost.Color = Color3.new(0, 0, 0)
	Ghost.Rotation = Rot
	
	local GhostImage = Instance.new("Decal", Ghost)
	GhostImage.Texture = "rbxassetid://13199053500"
	GhostImage.Face = "Top"
end)

Im working on this game where you build with logic gates, and i want to know how to be able to place stuff on a grid based system without overlapping.

It is possible that you could use :GetTouchingParts() (BasePart) or :GetPartsInBox (WorldRoot I believe).