``lua
local function placeBlock()
if isBuilding and selectedBlock then
local mouse = player:GetMouse()
local target = mouse.Target
if target and target.Parent then
local position = target.Position + target.CFrame.UpVector * (target.Size.Y / 2)
local newBlock = selectedBlock:Clone()
newBlock.CFrame = CFrame.new(position)
newBlock.Parent = game.Workspace
-- Weld the new block to nearby blocks
for _, block in ipairs(game.Workspace:GetChildren()) do
if block:IsA("Model") and block ~= newBlock then
local distance = (block.PrimaryPart.Position - newBlock.PrimaryPart.Position).Magnitude
if distance <= 4 then -- Adjust this value as needed
local weld = Instance.new("Weld")
weld.Part0 = block.PrimaryPart
weld.Part1 = newBlock.PrimaryPart
weld.C0 = block.PrimaryPart.CFrame:ToObjectSpace(newBlock.PrimaryPart.CFrame)
weld.C1 = newBlock.PrimaryPart.CFrame:ToObjectSpace(block.PrimaryPart.CFrame)
weld.Parent = block.PrimaryPart
end
end
end
end
end
end
``