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

How do I sort the values of several Integer Values from greatest to smallest?

Asked by 3 years ago

I have a folder with 12 integer values in it. As a round goes on the values of said integer values will change. I want to find a way to sort them from greatest to least.

Any help will be appreciated!

1 answer

Log in to vote
1
Answered by
yx10055 57
3 years ago
local IntFolder = script.Parent.ValueFolder -- Enter the path of your folder
local Highest = 0
local HighestObject

for _, v in pairs(IntFolder:GetChildren()) do
    if v:IsA("IntValue") then
        if v.Value > Highest then
            Highest = v.Value
            HighestObject = v
        end
    end
end

print(HighestObject:GetFullName())

This goes through the objects in your folder, checks if they are integer values, checks if their value is higher than the highest value, sets the highest value to their value and sets the highest object to the value.

0
You absolute legend! I'll throw this code in my game and see if it works. If it works I'll accept this answer. YelloMynamesZak 85 — 3y
0
YelloMynamesZak Did it work? yx10055 57 — 3y
0
It worked! Thanks for your help! YelloMynamesZak 85 — 3y
Ad

Answer this question