Weird Bug With My Mode Voting Script [CLOSED]

Hello, so I have a problem with my script:
Basically, there are two folders modeTickets (rs.lobbyEvents.modeTickets) - one called “infection” the other “tdm”.

In the function, there is a table that should insert both names of the folders. For some reason, it only inserts one of the folders & leaves the second one out. Causing :WaitForChild() to pick up a nil value when used to get mode2

I’m not really sure why this happens since there is clearly two folders…

function modeTicketChecked()
	local modeTickets = rs.lobbyEvents.modeTickets
	
	local modeTable = {}
	
	local winMode
	
	for i, mode in ipairs(modeTickets:GetChildren()) do
		if mode:IsA("Folder") then
			table.insert(modeTable, mode.Name)
			warn(modeTable)
			
			local mode1 = modeTickets:WaitForChild(modeTable[1])
			local mode2 = modeTickets:WaitForChild(modeTable[2])
			
			if #mode1:GetChildren() >= #mode2:GetChildren() then
				print(mode1.Name.." wins!")
				
				winMode = mode1.Name
				
				warn(winMode)
			elseif #mode2:GetChildren() >= #mode1:GetChildren() then
				print(mode2.Name.." wins!")
				
				winMode = mode2.Name
				
				warn(winMode)
			end
		end
	end
	
	return winMode
end

what

Let’s start by identifying if it’s actually being inserted. Write this after the warning:
print(#modeTable, modeTable)

The outcome we’re looking for is 2, {[1] = infection, [2] = tdm}
Please share your results here.

thte result is

1 { [1] = infection }

tdm isn’t being inserted

Problem solved, I had to move everything out of the for loop aside from the table.insert()

ouch…

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.