Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
0

How to get the highest value?

Asked by
DeepDev 101
7 years ago

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?

2 answers

Log in to vote
0
Answered by 7 years ago
Edited 7 years ago
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.

0
BTW, if your going to use this in a loop, in the end put Mapvotes = {} to clear the table User#17125 0 — 7y
0
Doesnt work. "ServerScriptService.RoundSystem.Script:12: 'then' expected near ','" DeepDev 101 — 7y
0
Whoops, lemme fix that User#17125 0 — 7y
0
fixed User#17125 0 — 7y
Ad
Log in to vote
1
Answered by 7 years ago

this is a simple solution


print(math.max(unpack(votes)))
0
LOl I was thinking of a really complex Solution. Thanks you helped me too GeezuzFusion 200 — 7y
0
It doesnt work, maybe I'm not clear but .MapVoted is a folder filled with intvalues named after maps. DeepDev 101 — 7y

Answer this question