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

BrickColor expected, but BrickColor is supplied?

Asked by
Edenojack 171
8 years ago

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?

2
string.sub doesn't return a number, it returns a string. Perci1 4988 — 8y

2 answers

Log in to vote
1
Answered by
Omarstein 100
8 years ago
local Cols = {BrickColor.new("Bright red"),BrickColor.new("Bright yellow"),BrickColor.new("bright blue")}

t.BrickColor = Cols[tonumber(string.sub(thingy, 2))]
Ad
Log in to vote
-1
Answered by
joalars2 107
8 years ago
Edited 8 years ago

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)])
0
No. User#11440 120 — 8y

Answer this question