To clarify this a bit, your for loop is already giving you pairs of information.
When you specify a paired loop like for i,v in pairs(TableVariable) do
-
i is your integer from an array OR i is the key from a dictionary. (Both can be referred to as Index)
-
v is your value
By using a paired loop, you are basically completing a localized list of commands/function for every pair of data. In your case, since DifficulyTable
is an array, you have _
representing your integer variable and d
representing your value variable.
Here’s an example dictionary and how a paired loop would use those variables.
local DictionaryExample = {
-- ["Key"] = Value
["NumberTest"] = 123
["BoolTest"] = false
["InstanceTest"] = Instance.new("Part")
}
for i,v in pairs (DictionaryExample) do --Each time this loop runs, it will supply a key (Variable i) with it's accompanying value (Variable v)
--> During one of the runs on the loop, i would be equal to the string "NumberTest" and v would equal the number 123.
--> During a different run, i would be equal to the string "BoolTest" and v would equal false.
--> etc.
end
Indexing an array with an integer, returns the value of what is in that placement in the array.
For example:
ArrayExample = { 123, false, Instance.new("Part") }
--ArrayExample[0] -> nil
--ArrayExample[1] -> 123
--ArrayExample[2] -> false
--ArrayExample[3] -> Part
Using a paired loop on an array already gives you it’s current placement in the form of an integer so you don’t have to create or increment your own variable (Order
).
for i,v in pairs (ArrayExample) do -->This goes through every value in the table in order.
--Variable i would be equal to v's placement in the array which happens to also be the current pass on the loop.
--For example (with this specific table): If v were to equal Part then i would be 3. If v were to equal 123 then i would be 1.
end
Because you are already receiving the keys and values from your script’s loop, you don’t need to index the table again with Order
, especially since during your first pass of the loop, you indexed it with 0 (which returned nil) resulting in an error when you tried to set a string property (Name) to nil. You can just reference the variable you made (d) that already represents the value of the loop’s current position in the array.
DifficultieFrameSchemeClone.Name
= DifficulyTable[Order]
DifficultieFrameSchemeClone.Name
= d