Like @JohhnyLegoKing said, you are using string keys for your table and then attempting to reference them with a number.
It seems like you are getting mixed up with the keys.
When you make an array, like this:
local myArray = {
"hi",
"bye",
"how are you today"
}
Lua actually formats it into this structure:
local myArray = {
[1] = "hi",
[2] = "bye",
[3] = "how are you today"
}
This allows you to do things like print(myArray[1])
, which would output “hi”.
The item on the left is the key, and the item on the right is the value, hence why you give two variables when iterating over it.
--ipairs() for numerical keys
--pairs() for string keys
for key, value in ipairs(myArray) do
print(key, value)
end
In your case, you have string keys.
local bubbleTable = {
["BlueBubble"] = 5000,
["PurpleBubble"] = 15000,
["PinkBubble"] = 50000,
}
To reference the first item in your array, you would do print(bubbleTable.BlueBubble)
, which would output 5000
.
In short:
- The item on the left is the key, the item on the right is the value which is associated with the key.
- When we reference items in an array we reference the key which is associated with the value we are trying to access.
- Keys can be numerical or string:
Numerical keys use [1]
(and etc.), things like GetChildren()
and GetDescendants()
return a numerical array.
String keys use a string. To reference the third item in your array, we would use bubbleTable.PinkBubble
.