Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
✓ ANSWER ACCEPTED

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

✓ Accepted answer

Try to concatenate the two variables.

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

Or.

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

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]

1 comment

0

this is EASIER

This discussion is preserved as it was. New answers, comments, and votes are closed.