Not printing brickColor!

So i made a script that gets a brickcolor from a table using an index, but it doesnt work, as when i return the value and try to print it, a blank space appears in ouput.
image
heres the function

local function getBrickColorFromIndex(num: int)
	local brickColors = {
		BrickColor.new("Red flip/flop"),
		BrickColor.new("Really red"),
		BrickColor.new("Really blue"),
		BrickColor.new("Black metallic"),
		BrickColor.new("Grey"),
		BrickColor.new("Slime green")
		
	}
	
	for i,v:BrickColor in pairs(brickColors) do
		if num == i then		
			return brickColors[i]
		end
	end
end

local function decodeBallCode(code:string)
	local NewCode = string.split(code,".")
	print(NewCode[1])
	print(getBrickColorFromIndex(NewCode[1]))
	return {getBrickColorFromIndex(NewCode[1]),getMaterialFromIndex(NewCode[2]),NewCode[3]}
end

Any issue im not seeing?

also an error from another part of the script
image

local translatedValues = decodeBallCode(v)
clone.BrickColor = translatedValues[1]

instead of doing this

for i,v:BrickColor in pairs(brickColors) do
		if num == i then		
			return brickColors[i]
		end
	end

, since you want num to equal i whenever you want to return brickColors, you can just

local function getBrickColorFromIndex(num: int)
	local brickColors = {...}	

	return brickColors[i]
end

Also what is the string that you’re passing in decobeBallCode()

The string im passing is “2.1.1”

I found the issue!
I needed to do NewCode[tonumber(1)]

was just about to send that in, well good job i guess! :D.

1 Like

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.