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

How do I use a variable and text in a text property?

I want to set the text of a hint to a variable with text. Like this:

game.workspace.Message.Text = "The game will start in (variable)"

How can I do that?

4 answers

✓ Accepted answer

This answer is mainly to clear up the two other answers.

Concatenation is basically a programmer word for joining things together.

To perform concatenation in Lua, all you need to do is add .. in the right places;

local currentTime = "5 PM"
local str = "The time is " ..currentTime.. "!" --// Notice the space between 'is' and the speech mark

print(str) --// prints 'The time is 5 PM!'

A concatenation will error when you try and concatenate values that have not had tostring() performed upon them (excluding numbers and objects).


Hope I helped!

~TDP

You're looking for this : Concatenation.

In your case it's going to be like this :

variable = "a couple of seconds..."
workspace.Message.Text = "The game will start in " ..variable

--The message should read : The game will start in a couple of seconds.

2 comments

0

It will actually say 'The game will start inacouple of seconds', because concatenation does not add spaces.

0

Correct. Edited it

Here is a example as how you can use variubles in text.

local Info = 123456
print("My info is "..Info.."!")

So what we want to do is

local TimeOfStart = 20 seconds
game.Workspace.Message.Text = "The game will start in "..TimeOfStart..". Please wait."

What this will put is "The game will start in 20 seconds. Please wait." If this answer is helpful, please accept the answer!

What you need to do is this.

game.workspace.Message.Text = ("The game will start in" variable )

1 comment

0

FALSE. You forgot your 2 dots aka periods

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