Hello ScriptingHelpers,
I'm trying to make a map voting system through a gui and store all votes in a intvalue. I.E:
game:GetService("ServerStorage").Folder.MapVotes.Map1 --etc.
With In pairs I got all values from the MapVotes Folder
local Votes= game:GetService("ServerStorage").RoundSystem.MapVotes:GetChildren() for i,v in pairs(Votes) do print(v.Value) end
But now I have trouble with getting the highest value A.K.A The most voted map. Could you guys please help and or explain me how I can get the Highest Value?
Mapvotes = {} table.insert(Mapvotes, game:GetService("ServerStorage").Folder.MapVotes.Map1.Value) table.insert(Mapvotes, game:GetService("ServerStorage").Folder.MapVotes.Map2.Value) table.insert(Mapvotes, game:GetService("ServerStorage").Folder.MapVotes.Map3.Value) --Etc. table.sort(Mapvotes) Highest = Mapvotes[#Mapvotes] if Highest == game:GetService("ServerStorage").Folder.MapVotes.Map1.Value then print("Map1") end elseif Highest ==game:GetService("ServerStorage").Folder.MapVotes.Map2.Value then print("Map2") end elseif Highest == game:GetService("ServerStorage").Folder.MapVotes.Map3.Value then print("Map3") end
this was a quick script utillizing tables.
Of course, this script doesn't account for ties, but works nontheless.
this is a simple solution
print(math.max(unpack(votes)))