Solving your problem
Just follow the algorithm you listed in your question.
Make a loop
Inside the loop create an IntValue
Give the IntValue a Parent and a random Value
Finish the loop
Print the biggest value out of all of the IntValues
You screwed up because you did not follow your own rules. Naturally, because of that, you cannot possibly completely expect to get the same result...
So let's follow your rules and finish steps 1 through 4, because it appears that you somewhat did that correctly, albeit in the wrong order.
for index = 1, 10 do
LoadLibrary("RbxUtility").Create("IntValue")({
Parent = workspace.Bag,
Name = "Variable" .. index,
Value = math.random(20)
})
end
Now we're done with 4/5 of it, and we did not screw up at all. Now, let's figure out how to do #5: Print the biggest value out of all of the IntValues.
How would you find the biggest value out of a bunch of numbers? I don't know about you, but this is how I would do it, step-by-step...
Go through each number
For each number, check it for...
2a. If this is the first number, then it is automatically the largest number out of all of the numbers we have checked so far (pause a bit and think about why this is true) OR if there is no largest number so far, then the number is automatically the largest number (this about this as well)
2b. If not #2a, then check if it is larger than the largest number out of all of the numbers we have checked so far. If it is, then the largest number out of all of the numbers we have checked so far including the current one is that number.
Finish going through each number
Print the largest number we found
Pretty simple, right? Let's turn that into code.
local largestNumber
for index, number in next, t do
if not largestNumber then
largestNumber = number
else
if number > largestNumber then
largestNumber = number
end
end
end
print(largestNumber)
Now, we just put the two portions together.
for index = 1, 10 do
LoadLibrary("RbxUtility").Create("IntValue")({
Parent = workspace.Bag,
Name = "Variable" .. index,
Value = math.random(20)
})
end
local largestNumber
for index, IntValue in next, workspace.Bag:GetChildren() do
local number = IntValue.Value
if not largestNumber then
largestNumber = number
else
if number > largestNumber then
largestNumber = number
end
end
end
print(largestNumber)
What to take from all of this
Most people cannot program something because they failed to make a step-by-step process outlining exactly what they want to happen, or because they cannot follow their process at all.
Do not be that sort of person. I am sure you realized by now that all of these steps that I listed were all easy things that you were probably thinking at one point or another but failed to follow. When you think of a plan of attack for writing a program, make sure you remember it and follow it to the letter.
Creating clear instructions and following instructions are arguably the two most important parts of programming; if you cannot make instructions clearly, then how do you expect your computer to possibly do what you want it to?