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

How would you do an f string in lua havent seen anything on the forums?

I was wondering in other programming languages like python you have f strings where you could add a variable in the middle of the printing how do you do this in roblox tho?

Example in a local script

local button = script.Parent

local player = game.Players.LocalPlayer

local text = "Hello, Playersnamehere welcome to the game" -- here you have where the player's name is which is referring to the local player.

button.Text = text -- changes the buttons text to the text above

2 answers

✓ Accepted answer

I forgot what it is called but you use .. (2 periods) for example

local Name = "BOB"
print("Welcome to the game" .. Name)

3 comments

0

Thank you so much Lifesaver!

0

That is called concatenation

0

I knew it started with a c lol

Yes, concatenation would accomplish what you need, although there is another method. You can format strings.

An example of this would be:

local Player = game.Players.LocalPlayer

local text = ("Hello, %s welcome to the game"):format(Player.Name)

or

local Player = game.Players.LocalPlayer

local text = string.format("Hello, %s welcome to the game", Player.Name)

1 comment

0

Thank you for your answer!

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