Attempt to perform arithmetic (sub) on nil and number

So, I’m trying to make this text work:

local ballChances = {
	RedBall = 70,
	BlueBall = 95,
	GreenBall = 100
}

for i,v in pairs(ballChances) do
    newBallGui.BallText.Text = "RNG: "..tostring(2 ^ (table.find(ballChances,i) - 1))
end

I tried to make the script short, but the index is equal to greenball or redball. but in the text I need the position of that ball, not the chance value, the index position in the table.

Does anyone know how to do that?

1 Like

Try this code:

what I did was changing the Format of your dictionary, it was not a table. I’d recommend you to format it like this. I then changed the i to v.

Lmk if it works

local ballChances = {
	
	{
		RedBall = 70,	
	},
	
	{
		BlueBall = 95,
	},
	{
		GreenBall = 100
	},

}


for i,v in pairs(ballChances) do
	newBallGui.BallText.Text = "RNG: "..tostring(2 ^ (table.find(ballChances,v) - 1))
end

They could do that, or they could just do ballChances[i] instead of table.find…

1 Like

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