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

[Answered] BrickColor values used as a key in a table?

Asked by
KarlXYZ 120
10 years ago

I'm trying to pull a value from a table that's relevant to a player's TeamColor eventually.

My table currently looks like this:

local incomeTable = {
    [BrickColor.new("Camo")] = 10,
    [BrickColor.new("Sand blue")] = 20,
    [BrickColor.new("Bright yellow")] = 30,
    [BrickColor.new("Bright red")] = 40,
    [BrickColor.new("Nougat")] = 50,
    [BrickColor.new("Royal purple")] = 60,
    [BrickColor.new("Pastel blue-green")] = 70,
    [BrickColor.new("Cool yellow")] = 80,
    [BrickColor.new("Navy blue")] = 90,
    [BrickColor.new("Teal")] = 100,
    [BrickColor.new("Deep blue")] = 110
}

Whenever I try printing a value from an example BrickColorValue object that's in ServerStorage which has the value Camo,

print(incomeTable[game.ServerStorage.Example.Value]) --BrickColor is the name of the object.

I get "nil" printed to the output... obviously I must have the wrong key names in the table. I should be getting "10" printed.

I've modified the table to this too:

local incomeTable = {
    ["Camo"] = 10,
    ["Sand blue"] = 20,
    ["Bright yellow"] = 30,
    ["Bright red"] = 40,
    ["Nougat"] = 50,
    ["Royal purple"] = 60,
    ["Pastel blue-green"] = 70,
    ["Cool yellow"] = 80,
    ["Navy blue"] = 90,
    ["Teal"] = 100,
    ["Deep blue"] = 110
}

And got the same result as the table above...

Any help would be appreciated.

2
Not posting this in an answer because I'm not sure. Try the second example, but try converting the value in ServerStorage to a string using tostring(). Perci1 4988 — 10y
0
Works! Thank you very much. :) KarlXYZ 120 — 10y

Answer this question