Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
COMMUNITY QUESTION

BrickColor expected, but BrickColor is supplied?

I'm storing Colours in a table to be able to call them depending on a random number (1,3)

set up like this,

local Cols = {BrickColor.new("Bright red"),BrickColor.new("Bright yellow"),BrickColor.new("bright blue")}

and I'm calling it like this:

t.BrickColor = Cols[string.sub(thingy, 2)]

t is defined and the string.sub will always produce a number between 1-3 but it keeps throwing up the error: ServerScriptService.GEN R 8:21: bad argument #3 to 'BrickColor' (BrickColor expected, got nil) even though it is supplied. Wat. What am I missing here?

1 comment

2

string.sub doesn't return a number, it returns a string.

2 answers

local Cols = {BrickColor.new("Bright red"),BrickColor.new("Bright yellow"),BrickColor.new("bright blue")}

t.BrickColor = Cols[tonumber(string.sub(thingy, 2))]

You're not using BrickColor.new()

This is how it should look like;

local Cols = {BrickColor.new("Bright red"),BrickColor.new("Bright yellow"),BrickColor.new("bright blue")}

t.BrickColor = BrickColor.new(Cols[string.sub(thingy, 2)])

1 comment

0

No.

This discussion is preserved as it was. New answers, comments, and votes are closed.