Determine highest amount of children

i am trying to get the one with the highest votes but it often chooses a different one with no votes. what is this script doing wrong?


	local highestVoted = nil

	for i, PadBlockObjectValue in pairs(script.PADS:GetChildren()) do
		if not highestVoted then
			highestVoted = PadBlockObjectValue
		else
			if #PadBlockObjectValue.Value.Votes:GetChildren() > #highestVoted:GetChildren() then 
				highestVoted = PadBlockObjectValue
			elseif #PadBlockObjectValue.Value.Votes:GetChildren() == #highestVoted:GetChildren() then 
				local mapsToChoose = {PadBlockObjectValue, highestVoted}
				highestVoted = mapsToChoose[math.random(#mapsToChoose)]
			end
		end
	end
1 Like

shouldnt it count highestvoted.value.votes and not the whole body

1 Like