How to get the highest IntValue from a folder

You can write your topic however you want, but you need to answer these questions:

  1. What do you want to achieve? Keep it simple and clear!

I want to make a script that gets the highest intvalue from a folder(I am making a vote a map system)

  1. What is the issue? Include screenshots / videos if possible!

I have no idea how to do that

  1. What solutions have you tried so far? Did you look for solutions on the Developer Hub?
    I heard about table.sort but I don’t understand it

use for i, v in pairs() to get all childrens then if v:IsA("IntValue") to see if it is a int value, then do a variable named highest then control if it is bigger or less, ill send you the script soon, i am writing it.

Script :


function GetBiggestValue(folder)
    local highestValue = nil
    for _, value in pairs(folder:GetChildren()) do

        if value:IsA("IntValue") then

            if highestValue == nil then
                highestValue = value 
            elseif highestValue.Value < value.Value then
                highestValue = value
            end

        end

    end

    return highestValue.Name
end

function GetHighestValue(Folder)
	local HighestValue = nil
	
	for i,v in pairs(Folder:GetChildren()) do 
		if v:IsA("IntValue") then 
			if HighestValue == nil then 
				HighestValue = v
			else
				if v.Value > HighestValue.Value then 
					HighestValue = v
				end 
			end
		end
	end
	
	return HighestValue
end	
	
print(GetHighestValue(game:GetService("Workspace").Values))

image

why you dont use elseif ?

I may be wrong, but the function returns the highest value as a number, but I need to get the name of the intvalue to know what map won

this will return the highest int value
it will not return the number it will return the highest value instance

and I need the name of the highest intvalue

okay i will edit it
char limit

Yeah you could use table.sort for a shorter solution

local Values = --path to your values folder

local function GetHighestValue(): IntValue
	local intVals = Values:GetChildren()
	table.sort(intVals, function(Higher, Lower)
		return Higher.Value > Lower.Value --sort from highest to lowest
	end)
	return intVals[1] --returns intvalue with highest value
end

i edited it now it will return it’s name