Make block placement not spawn in an existing part?

i have a part placement script, but when i place my mouse in one place, i can do it 2+ times, how do i make it check if there is an exiting part?
here is the script:

wait()
local player = game.Players.LocalPlayer
local mouse = player:GetMouse()
local UIS = game:GetService('UserInputService')
local RS = game:GetService('ReplicatedStorage')
local tool = script.Parent
local Event = RS:WaitForChild('PlaceBlock')
local pos
equipped = false
local part = game.ReplicatedStorage.Blocks.Part:Clone()

part.Click:Destroy()
-- Surface Detection

local function Surface(surface)
	if surface.Name == "Top" then
		pos = Vector3.new(0,4,0)
	elseif surface.Name == "Bottom" then
		pos = Vector3.new(0,-4,0)
	elseif surface.Name == "Front" then
		pos = Vector3.new(0,0,-4)
	elseif surface.Name == "Back" then
		pos = Vector3.new(0,0,4)
	elseif surface.Name == "Left" then
		pos = Vector3.new(-4,0,0)
	elseif surface.Name == "Right" then
		pos = Vector3.new(4,0,0)
	end
	return pos
end




local num = 1
local blocks = RS.Blocks:GetChildren()
local Block_Choice = blocks[1]

numberOfBlocks = #blocks


script.Parent.Activated:Connect(function()
	local target = mouse.Target
	if target then
		local surface = mouse.TargetSurface
		local pos = part.Position--Surface(surface)
		Event:FireServer(target,pos,Block_Choice)
	end
end)

-- the selection part 
mouse.Move:Connect(function()
	if equipped == true then

		part.CanCollide = false

		part.Parent = workspace
		mouse.TargetFilter = part
		local x = mouse.Hit.X
		local y = mouse.Hit.Y 
		local z = mouse.Hit.Z
		part.Position = Vector3.new(math.floor(x/4) * 4, math.floor(y/4) * 4 + 2, math.floor(z/4) * 4)

	end
end)
tool.Equipped:Connect(function()
	equipped = true

	part.Transparency = 0.5

end)

tool.Unequipped:Connect(function()
	equipped = false

	part.Transparency = 1
	part.Position = Vector3.new(1,1,1)

end)
1 Like

you should probably see if it collides with any other object around it using BoundingBox

(Model | Roblox Creator Documentation)

isn’t that for models,this is just a part