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

How to call a table with a string?

Asked by 4 years ago
Edited by royaltoe 4 years ago
-- Color tables
colors = {"blue", "red", "orange", "green"}
--table = {light color, dark color}
blue = {"Pastel Blue", "Cyan"} red = {"Persimmon", "Really Red"} orange = {"Gold", "Deep orange"} green = {"Shamrock", "Lime green"}

-- Changes tycoon template colors
local spawns = game.workspace.Tycoon_Spawns:GetChildren()
game.workspace.Tycoons.ChildAdded:connect(function(child)
    local value = child:GetDescendants()
    local random_color = math.random(1, #colors)
    local ran_color = colors[random_color]
    local str = Instance.new("StringValue", child)
    str.Name = "Tycoon_Color"
    str.Value = ran_color
    table.remove(colors, random_color)
    for i = 1, #value do
        local color = child.Tycoon_Color.Value
        print(color)
        if value[i].Name == "light" then
            print(color[1])
        end
        if value[i].Name == "dark" then
            print(color[2])
        end
    end
end)

0
Your going to have to give more info then that... firestarroblox123 440 — 4y
0
like itll pick a random color name and call that table like color[1] and ittl call blue[1] or red[1] but instead it just goes nil ComplexCrypt -5 — 4y
0
Learn about dictionaries / associative arrays. Have a table of tables, indexed by "blue", "red", etc. Look up the required table with `subTable = superTable[colourName]`. fredfishy 833 — 4y

Answer this question