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

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

Asked by 3 years ago

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

Log in to vote
1
Answered by 3 years ago

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

local Name = "BOB"
print("Welcome to the game" .. Name)
0
Thank you so much Lifesaver! johnoscarbhv1 137 — 3y
0
That is called concatenation appxritixn 2235 — 3y
0
I knew it started with a c lol JustinWe12 723 — 3y
Ad
Log in to vote
4
Answered by
appxritixn 2235 Moderation Voter Community Moderator
3 years ago

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)
0
Thank you for your answer! johnoscarbhv1 137 — 3y

Answer this question