Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
0

Why is the table not working with the variable?

Asked by 6 years ago
local myTable = {one = Color3.fromRGB(255, 255, 255), two = Color3.fromRGB(0, 0, 0)}
local myVariable = "one"
myTable[myVariable]

How would i make this work. I want it to take the variable from local myVariable not look in the table for myVariable. How would I do this?

1 answer

Log in to vote
0
Answered by 6 years ago

Well, your table doesn't define "one" as a string so you have to do

local myTable = {["one"] = Color3.fromRGB(255, 255, 255), ["two"] = Color3.fromRGB(0, 0, 0)}
local myVariable = "one"
myTable[myVariable]
Ad

Answer this question