Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
✓ ANSWER ACCEPTED

How to get the highest value?

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

✓ Accepted answer
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.

4 comments

0

BTW, if your going to use this in a loop, in the end put Mapvotes = {} to clear the table

0

Doesnt work. "ServerScriptService.RoundSystem.Script:12: 'then' expected near ','"

0

Whoops, lemme fix that

0

fixed

this is a simple solution


print(math.max(unpack(votes)))

2 comments

0

LOl I was thinking of a really complex Solution. Thanks you helped me too

0

It doesnt work, maybe I'm not clear but .MapVoted is a folder filled with intvalues named after maps.

This discussion is preserved as it was. New answers, comments, and votes are closed.