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 3 years ago

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

local PlanetNameHolder = script.Parent

local NameGenerate = math.random(1,3)

local SurnameGenerate = math.random(1,3)

if NameGenerate == 1
then local Name = "LOL"
elseif NameGenerate == 2
then local Name = "Bad"
elseif NameGenerate == 3
then local Name = "Nice"

if SurnameGenerate == 1
then local Surname = "Planet"
elseif NameGenerate == 2
then local Surname = "Rock"
elseif NameGenerate == 3
then local Surname = "Ball"
PlanetNameHolder.Name = (Name)(Surname)

    end 
    end


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 3 years ago
Edited 3 years ago

Try to concatenate the two variables.

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

Or.

PlanetNameHolder.Name = tostring(Name.. " ".. Surname)
Ad
Log in to vote
0
Answered by 3 years ago
Edited 3 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!

local PlanetNameHolder = script.Parent
local NameGenerate = math.random(#prefix)
local SurnameGenerate = math.random(#surname)

prefix = {
    'LOL',
    'Bad',
    'Nice'
}

surname = {
    'Planet',
    'Rock',
    'Ball'
}
--you may need to do PlanetNameHolder.Name or PlanetNameHolder.Value here
PlanetNameHolder = prefix[NameGenerate]..surname[SurnameGenerate]
0
this is EASIER skeletonpiratejack 13 — 3y

Answer this question