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

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

Asked by 7 years ago

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

Log in to vote
0
Answered by 7 years ago

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

Ad
Log in to vote
0
Answered by 7 years ago
Edited 7 years ago

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.
0
It will actually say 'The game will start inacouple of seconds', because concatenation does not add spaces. TheDeadlyPanther 2460 — 7y
0
Correct. Edited it strongrussianboy123 68 — 7y
Log in to vote
0
Answered by 7 years ago

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!

Log in to vote
-1
Answered by
cc567 50
7 years ago

What you need to do is this.

game.workspace.Message.Text = ("The game will start in" variable )
0
FALSE. You forgot your 2 dots aka periods SH_Helper 61 — 7y

Answer this question