For loop going through the same value twice?

The title already explains it all. This is my script. I’ve been trying to fix this for almost 7 and a half hours now, so if you know how to fix it, please do! Thanks.

Script Context
This is for a tycoon and the “Unlocks” is a folder for everything a button unlocks.
This script is in server script service so it uses tags to get all buttons
ChildrenOfBought technically ChildOfBought but I didn’t feel like chaning it
ChildOfBought is basically everything inside of Unlocks.
Before the game starts, it turns all the unbought stuff invisible.

Script


function PressurePlateButtons(v)
	if v.Name ~= "StartButton" then
		v.Transparency = 1
	end

	local pressurePlate = v
	local base = pressurePlate:FindFirstAncestor("BASE")

	local droppers = {}
	local transparencies = {}

	local function fadeTween(part, goal, Time)
		ts:Create(part, TweenInfo.new(Time, Enum.EasingStyle.Sine, Enum.EasingDirection.InOut), goal):Play()
	end

-----------------------THIS IS THE WHILE LOOP THE PROBLEM IS HAPPENING IN!!!
	local function vis(parent, turnInVis, Time, onlyInUnlocks, invLabel)
		for i, childrenOfBought in pairs(parent:GetChildren()) do
			wait()
			print(childrenOfBought)
			if childrenOfBought.Name ~= "Unlocks" and not transparencies[childrenOfBought.Name] then 
				print("Went", childrenOfBought)
				if turnInVis == 1 then--invisible
					local s, f = pcall(function()
						repeat wait() print("waiting", childrenOfBought, childrenOfBought.Transparency, childrenOfBought.Parent.Parent) transparencies[childrenOfBought.Name] = {childrenOfBought.Transparency} until transparencies[childrenOfBought.Name][1] ~= 1
						print("Donee", childrenOfBought)
						coroutine.wrap(fadeTween)(childrenOfBought, {Transparency = turnInVis}, Time)
					end)
					print(f, childrenOfBought)

					local s, f = pcall(function()--TextLabels don't have CanCollide so if I put this in the other pcall, it would break the whole function for the TextLabel
						transparencies[childrenOfBought.Name][2] = childrenOfBought.CanCollide
						childrenOfBought.CanCollide = false
					end)
					print(f, childrenOfBought)

				else--visible
					print("visible", childrenOfBought)
					local _, fail = pcall(function()
						coroutine.wrap(fadeTween)(childrenOfBought, {TextTransparency = invLabel}, Time)
					end)
					print(childrenOfBought, fail)

					if fail then
						if transparencies[childrenOfBought.Name] then
							print(childrenOfBought)

							childrenOfBought.CanCollide = transparencies[childrenOfBought][2]
							coroutine.wrap(fadeTween)(childrenOfBought, {Transparency = transparencies[childrenOfBought][1]}, Time)
							print(transparencies[childrenOfBought], childrenOfBought.Transparency, childrenOfBought.CanCollide, childrenOfBought)
						end
						print(childrenOfBought)
					end
					warn(transparencies)
					print(childrenOfBought, fail)

				end
				
				vis(childrenOfBought, turnInVis, Time, "Unlocks", invLabel)

			end

		end
	end



	--FindDroppers
	for i, v in pairs(pressurePlate.Unlocks:GetChildren()) do
		if (v.Name:lower():match(("Dropper"):lower())) and not v:HasTag("Button") then
			table.insert(droppers, v)

		end
	end
	
	--Invis all Unlocks
	vis(pressurePlate.Unlocks, 1, 0, "GoThroughAllUnlocks", 0)
	
	
	local touched = false
	local c
	c = pressurePlate.Touched:Connect(function(toucher)
		if touched == true then return end
		if not toucher.Parent:FindFirstChild("Humanoid") then return end
		local char = toucher.Parent
		local plr = game:GetService("Players"):GetPlayerFromCharacter(char)
		if pressurePlate.Transparency == 1 then return end
		if not plr then return end
		touched = true
		c:Disconnect()


		pcall(function()pressurePlate.Head:Destroy() pressurePlate.BillboardGui.TextLabel.TextTransparency = 1 end)


		fadeTween(pressurePlate, {Transparency = 1}, 1)
		--fadeTween(pressurePlate.BillboardGui.TextLabel, {TextTransparency = 1}, 1)


		vis(pressurePlate.Unlocks, 0, 1, "Unlocks", 0)



		for i, dropper in pairs(droppers) do
			local Type, IndexNum = MakeDropper.FindType(dropper)
			local dropperTable = MakeDropper.NewDropper(dropper, Type, base, toucher.Parent)
			if dropperTable then
				dropperTable:Drop()
			end
		end

	end)	
end


for i, v in pairs(cs:GetTagged("Button")) do
	--Script by BlueBLoxBlast(Ask me if something broke)
	task.wait(.0)
	PressurePlateButtons(v)



	--very interesting
end

isGameReady = true

warn("LOADTIME LOADTIME LOADTIME LOADTIME LOADTIME", tick() - start)

I briefly looked into the script and it’s kinda messy but I didn’t find any huge logical errors and stuff. Did you accidentally put two same scripts in the game so it goes through the same value twice?

Also, would you mind giving more context about “for loop going through the same value twice”? And what you expected to happen and what happened. I’m bad at english so I didn’t really understand

You are calling vis() twice.

Not sure if you want to or not:

I do want it. I invis all unlocks at the start because the player hasn’t bought the unlocks yet. Some stuff, like a dropper is a model that has more than one part. That’s why I make it call the function again.

Like let’s say we’re going through the for loop with the start button’s children. It goes to the first child, and looks at THAT CHILD’s children, and then keeps going through the children of children of children of children. And it keeps repeating that same process every time the for loop moves to the next child of the start button.