Math.random(#table) Printing Number Instead of a String

Code:

local textx = {"Shift to run", "Taxis are the most advanced","Normal cars are slow","Police car and taxi are the faster cars, but bigger cars have more health","Camping at the border is a smart move, but it may be overrun","The citizens are crazy and thats why they go out of there way to kill you"}

script.Parent.Text = math.random(#textx)


-- BEFORE YOURS SAY ANYTHING, The method I used to pick a random string works. It's just the fact that it's printing a number instead of a string

My problem is in the title

math.random function returns a number, you need to use that number as an indexer on the table to get a random string value from the table:

script.Parent.Text = textx[math.random(#textx)]
2 Likes

my thoughts exactly. looks like “the method you used to pick a random string” doesn’t actually work.

That worked. That is weird considering the fact that I used math.random(#table) method to get strings before

Yea sorry i’m not that experienced with stuff like this

eh, no worries.

This text will be blurred

1 Like

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