Say there was a list of IntValues in a folder. I need to find the greatest value of all of the values.
Should I use a for loop? What would I do?
I would use a for loop. Example:
local folder = game.Workspace:WaitForChild("Folder") --put your folder name there, also change the Workspace part if needed.
local greatestVal = 0
local greatestValObject
function findGreatestValue()
greatestVal = 0
for I,v in pairs(folder:GetChildren()) do
if v.Value > greatestVal then
greatestVal = v.Value
greatestValObject = v
end
end
print("The greatest value is "..greatestValObject.Name)
end
findGreatestValue()
Then, whenever you call that function, it should loop through the folder and print the variable that has the greatest value! Let me know if there are any bugs, haven’t tested the code yet.
Edit: tested this latest code, it works just fine!
1 Like