Stop function when button is pressed

I wish to create a building system where when the player presses a button it places a model, though I would also like it so when the player presses a different button it replaced the model which was set from the previous button. Currently, when a player clicks a button it runs the placement function with the button name, which allows the player to place a model when they click on a suitable area. How do I cancel the ‘placeStructure’ function after a new button is pressed?. I am unsure of how to do this, Could someone please give me some help?

Current button/model selector script:

for i, Button in pairs(script.Parent.Buttons.Frame:GetChildren())do
	if Button:IsA("TextButton")then
		Button.MouseButton1Up:Connect(function()
			local structure = Button.Name
			placeStructure(structure)
		end)
	end
end

You could Disconnect the event after calling the function, but you need to define a variable to the event first

local mouseConnection
mouseConnection = Button.MouseButton1Up:Connect(function()
	local structure = Button.Name
	placeStructure(structure)
    mouseConnection:Disconnect()
    mouseConnection = nil -- completely remove the mouseConnection variable
end)

My bad, Instead of disconnecting the click function, I want to disconnect the placeStructure() function.