0

# how to use variable with space?

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
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!

0
Edited 2 months ago

Try to concatenate the two variables.

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


Or.

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

0
Edited 2 months 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',
'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 — 1mo