Hello! I am working on a realistic american football game and ran into an issue as I don’t know how to do something. I have int values, that once a player joins, anywhere from 1 - 16 intvalues are created (randomized). The value of the intvalue is randomized as well. How would I make a table, script, whatever to where I can search through the entire folder and I can find which intvalue has the highest value?
Loop through all the values and store them in a table. Then utilize the table.sort function.
Don’t use a sort function just to find one element. table.sort uses quicksort, I think, which has a O(n^2) complexity in the worst case. The traditional min/max runs in O(n) time.
local function maxValue(folder)
local values = folder:GetChildren()
local highest = values[1]
for _, value in ipairs(values) do
if (value.Value > highest.Value) then
highest = value
end
end
return highest
end
Thanks! I used your table and made some changes to make it more efficient with what I am trying to accomplish. I decided to just make a new int value, and keep setting that int value to the highest.