Why is this printing multiple values?

I’m working on a round system right now, basically, players will have 3 options to choose from, they will then be shown on a gui to vote (similar to Arsenal). Once voted, it creates a string value with the name of the player who voted in a folder named Votes. Basically, I have this code here, and instead of only printing one map, it prints all of them but the output does this:
23:00:46.746 - map6 was chosen! 23:00:46.747 - map7 was chosen! (x2)

When map7 was the one I voted for. How can I fix this problem?

local selectedMaps = workspace.queuedMaps
local highestVoted
for i,vote in pairs(selectedMaps:GetChildren()) do		
	if not highestVoted then highestVoted = vote end
    if #vote.Votes:GetChildren() > #highestVoted.Votes:GetChildren() then 			
        2highestVoted = vote
	elseif #vote.Votes:GetChildren() == #highestVoted.Votes:GetChildren() then 		
		local mapsToChoose = {vote, highestVoted}
		highestVoted = mapsToChoose[RNG:NextInteger(1, #mapsToChoose)]		
	serverClient:FireAllClients("mapChosen", highestVoted.Name)

If you are able to help, thank you. If not, have a great rest of your day!

1 Like

It’s printing twice because you are using a “for loop”. and “for i,vote in pairs(selectedMaps:GetChildren()” just means that whatever “selectedMaps” is, it has 2 things or children inside it. so it’s printing twice for both things.

1 Like

Yes, there are 3 maps, I’m trying to find the map that has the most votes. And then if it’s a tie, there is a Random.new to choose one map.

1 Like

Found the solution. I had to move the serverClient:FireAllClients("mapChosen", highestVoted.Name) one line down.

You should mark the above post as the solution.