Building tool duplicating part when selecting new color

I’m making a building system, and when you select a color, it works, but when you select another one, it will duplicate, and will continue duplicating the parts.

Video:

Help?

You have to disconnect the Block function from Button1Down after it is done.

local con; con = mouse.Button1Down:Connect(function()
	Block()
	con:Disconnect()
end)

You can simply disconnect the event like here:

local mouse  =  player:GetMouse()
local frame = script.Parent.Colors
local Color = nil

--BlockFunction
local function Block()
	local position = mouse.Hit.p
	local Brick = Instance.new("Part")
	Brick.Name = "Part placed by "..player.Name
	Brick.Parent = workspace
	Brick.Color = Color
	Brick.Size = Vector3.new(4, 4, 4)
	Brick.CFrame = CFrame.new(position)
	Brick.Anchored = false
end

--ChosingColor
for i,v in pairs(frame:GetChildren()) do
	if v:IsA("ImageButton") then
		v.Activated:Connect(function()
			print(v.BackgroundColor3)
			Color = v.BackgroundColor3
			con = mouse.Button1Down:Connect(Block)
            con:Disconnect()
		end)
	end
end

That won’t work as you disconnect the Block function immediately after connecting it.

I’m sure it works, but for some reason, on my end, Studio is not detecting con as a variable.
image
Bit odd, but I’m sure if I relaunch Studio it would be fine.

Oops, forgot Roblox’s Lua doesn’t allow recursive declarations. Replace local con = with local con; con =.

Ah, alright. Thanks for the help!

Edit: After some more testing, I realized that with the solution I set, it would require the user to click the color every time they want to place a block down.