How can I get a string from a table?

You can write your topic however you want, but you need to answer these questions:

  1. What do you want to achieve? I want to get a string from a table.

  2. What is the issue? It prints the number instead image

FirstNames = {"Hana","Zoya","Willie","Nettie","Kara","Jack","Adam","Zak","Lucas","Mark","Laza","Lianna","Nancy","Maraiyah","Karen"};
 LastNames = {"Frank","Brooks","Ward","Watson","Waters","Wilkerson","Kirk","Hale","Simmons","Flores","Woodward","Crawford", "Owen","Simmons","Singh","Li"};

local FirstName =math.random(1,#First_Names)
local LastName = math.random(1,#Last_Names)
print(tostring(FirstName) .. tostring(LastName))

Of course it prints the number because you didn’t even index the table with the random number. You should’ve:

local firstNumber = FirstNumberList[RandomNumber]

And do the same thing with the second table.

To what you said, it kinda actually works.
Here’s the script.

FirstNames = {"Hana","Zoya","Willie","Nettie","Kara","Jack","Adam","Zak","Lucas","Mark","Laza","Lianna","Nancy","Maraiyah","Karen"};
LastNames = {"Frank","Brooks","Ward","Watson","Waters","Wilkerson","Kirk","Hale","Simmons","Flores","Woodward","Crawford", "Owen","Simmons","Singh","Li"};

local firstNum = math.random(1, #FirstNames)
local lastNum = math.random(1, #LastNames)
local FirstName = FirstNames[firstNum]
local LastName = LastNames[lastNum]
print("".. FirstName .." ".. LastName)

The Output:

$lua main.lua
Nancy Kirk

But the problem is, it only prints Nancy Kirk.

3 Likes

It should work now, you can mark my comment as a solution of this post.