# How can I get the map with the highest votes correctly?

Hey!

So I made a script which decides what’s the map with the highest votes.
However, it’s not optimized, and it has some issues.
So I wanna know I can improve the way I did it.

## My current code

``````local chosenMap

end
end
end
end
``````

Thanks, bye!

2 Likes

you can use this

``````function PickHigh(fv1)
local High = 1
for i, v in pairs(fv1) do
if v > fv1[High] then
High = i
end
end
return fv1[High]
end

``````
1 Like

Won’t there be any issues when the votes will be equal?

nope, it will work completely fine. it will choose the first map among the equal maps in that case.

1 Like

Oh that’s perfect then!
Lemme test this out and see if it works
Thanks a lot for helping!

1 Like

Okay so I tested it.
And the only problem is that it changes the ChosenMap value to a number.
But I want it to be changed to the name of the map

Oh, you can use this code for that

``````function PickHigh(fv1)
local High = 1
for i, v in pairs(fv1) do
if v.Value > fv1[High] then
High = i
end
end
return fv1[High]
end
``````
1 Like

I got this error idk why
Line 208 is this: ` if v.Value > fv1[High] then`

can you send screen short of explorer where blocksVotes and stuffs are present

1 Like

`VotesAmount` is the amount of votes for that map

And `blocksVotes` is a variable for `Blocks.VotesAmount` ?

1 Like

Yes exactly

Oh sorry, got the error. here’s the fixed code

``````function PickHigh(fv1)
local High = 1
for i, v in pairs(fv1) do
if v.Value > fv1[High].Value then
High = i
end
end
return fv1[High]
end