MouseClick function in for i,v loop keeps older variables

Hello! I’m currently having an issue with my script keeping older variables, in this case “clicker”, when I print it out in the MouseClick function. So, in the output it shows all the previous variables of it. I tried disconnecting the function, but that doesn’t seem to work. Does anyone know if I can erase the script’s memory of the past clicker variable?

for i,v in ipairs(entire:GetChildren()) do
	if v.ClassName == "Model" and v.Remain.Value == true then
		v.Click.Value = false
		clicker = v:FindFirstChild(tostring(direc))
		clicker.BrickColor = BrickColor.new("Lime green")
		v.Value.Value = clicker
		for i,part in pairs(v:GetChildren()) do
			if part.ClassName == "Part" then
				local connection 
				local function onPartClick()
					if tonumber(num) > 0 then
						if part ~= part.Parent.Value.Value then
							part.BrickColor = BrickColor.new("Really red")
							v.Remain.Value = false
							connection:Disconnect()
						elseif part == part.Parent.Value.Value then
							part.BrickColor = BrickColor.new("Institutional white")
							v.Click.Value = true
							connection:Disconnect()
						end
					end
				end
				connection = part.ClickDetector.MouseClick:Once(onPartClick)
			end
		end
	end
end