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

how to use variable with space?

Asked by 4 years ago

i am trying to make a planet name generator so heres the code:

01local PlanetNameHolder = script.Parent
02 
03local NameGenerate = math.random(1,3)
04 
05local SurnameGenerate = math.random(1,3)
06 
07if NameGenerate == 1
08then local Name = "LOL"
09elseif NameGenerate == 2
10then local Name = "Bad"
11elseif NameGenerate == 3
12then local Name = "Nice"
13 
14if SurnameGenerate == 1
15then local Surname = "Planet"
View all 23 lines...

what i am having problem with is i have no idea how to put space on variables and i tried searching for it but still no answer so any help appreciated Any help appreciated!

2 answers

Log in to vote
0
Answered by 4 years ago
Edited 4 years ago

Try to concatenate the two variables.

1PlanetNameHolder.Name = (Name.. " ".. Surname)

Or.

1PlanetNameHolder.Name = tostring(Name.. " ".. Surname)
Ad
Log in to vote
0
Answered by 4 years ago
Edited 4 years ago

Here's a better way of achieving what you're looking for. To avoid the if else mess just use tables, and to avoid changing the random() calls use the length of the table. Wallah!

01local PlanetNameHolder = script.Parent
02local NameGenerate = math.random(#prefix)
03local SurnameGenerate = math.random(#surname)
04 
05prefix = {
06    'LOL',
07    'Bad',
08    'Nice'
09}
10 
11surname = {
12    'Planet',
13    'Rock',
14    'Ball'
15}
16--you may need to do PlanetNameHolder.Name or PlanetNameHolder.Value here
17PlanetNameHolder = prefix[NameGenerate]..surname[SurnameGenerate]
0
this is EASIER skeletonpiratejack 13 — 4y

Answer this question