Heartbeat:Disconnect not* disconnecting properly

I am currently making a script for when you click a button, you get to place a certain part down. Everything is working fine except for one major issue I noticed with the code. The issue is that when I place the part down, if I click again on nothing (it cannot be a button or anything else or it wont happen), a clone of that part will also spawn. This is strange because the heartbeat is made to disconnect and I can verify it is not disconnecting, ever, because of a print statement I put.

The code:
(this is gonna be long, sorry)

local player = game.Players.LocalPlayer
local mouse = player:GetMouse()
local runservice = game:GetService("RunService")
local revent = script.Parent.PlaceTurret
local frame = script.Parent
local confirmplaces = script.Parent.ConfirmPlaces

local placeable = false
local cancel = false

for i,v in pairs(script.Parent:GetChildren()) do
	if v:IsA("TextButton") and v.Name ~= "Close" then
	
		v.MouseButton1Click:Connect(function(c)
			local tchild = v:GetChildren()
			local t = tchild[1]:Clone()
			t.Parent = game.Workspace
			mouse.TargetFilter = t
			local y = t.Size.Y 
			local yOffset = y/2
			
			cancel = false
			placeable = true
			
			local heartbeat
			--tween placing menu to the side and disable all the buttons so you Can Avoid Glitches!
			script.Parent.Position = UDim2.new(-0.3,0,0.453,0)
			
			--disable all turret placement buy buttons
			for i,v in pairs(script.Parent:GetChildren()) do
				if v:IsA("TextButton") and v.Name ~= "Close" then
					v.Active = false
				end
			end
			
			--bring up cancel button
			script.Parent.Parent.Cancel.Position = UDim2.new(0,0,0.9,0)
			script.Parent.Parent.Cancel.Active = true
			
			heartbeat = runservice.Heartbeat:Connect(function()
				--move to mouse position
				t.Position = mouse.Hit.Position + Vector3.new(0,yOffset,0)

				--make ray to check if on Viable Ground!
				local castRay = Ray.new(mouse.UnitRay.Origin, mouse.UnitRay.Direction * 1000)
				local ignoreList = {t, player.Character}
				local raycast, position = workspace:FindPartOnRayWithIgnoreList(castRay, ignoreList)

				--make sure on "ground"
				if raycast then
					local hit = raycast
					local placesleft = confirmplaces:InvokeServer()
					if hit.Name == "ground" and placesleft > 0 then
						t.BrickColor = BrickColor.new("Bright green")
						placeable = true
					else
						placeable = false
						t.BrickColor = BrickColor.new("Crimson")
					end
				end
				
				--end if cancelled
				frame.Parent.Cancel.MouseButton1Click:Connect(function()
					cancel = true
					
					--move everything back
					frame.Parent.Cancel.Position = UDim2.new(-0.3,0.0,9,0)
					frame.Parent.Cancel.Active = false
					frame.Position = UDim2.new(0,0,0.453,0)
					t:Destroy()
					
					heartbeat:Disconnect()
				end)
				
				--place part
				mouse.Button1Down:connect(function()
					print("Click")
					if placeable == true and cancel == false then
						placeable = false
						--place and stuff
						revent:FireServer(tchild[1].Name, t.CFrame, frame, placeable)
						t:Destroy()
						
						--move back cancelbutton
						frame.Parent.Cancel.Position = UDim2.new(-0.3,0,0.9,0)
						frame.Parent.Cancel.Active = false
						
						--move building menu back to position
						script.Parent.Position = UDim2.new(0,0,0.453,0)
						
						for i,v in pairs(script.Parent:GetChildren()) do
							if v:IsA("TextButton") and v.Name ~= "Close" then
								v.Active = true
							end
						end

						heartbeat:Disconnect()
					end
				end)
			end)
		end)
		
	end
end

Can putting a runservice inside of a button mousebutton1click event cause this issue?

Just taking a quick skim through this, you have a mouse.Button1Down and a MouseButton1Click inside your heartbeat, I don’t think this is intentional, as you’re basically creating a new connection to these events on each heartbeat, which could be causing an issue. Maybe move them outside of the heartbeat and see if that helps

Ill try that out now and tell you the results

I just moved the MouseButton1Click out of the runservice and I am still facing the same issue.

Can you put a print statement in your MouseButton1Click which is intended to close the heartbeat and see if it results anything?

It prints the statement every time I click multiple times, not just once