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

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

Asked by 2 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
Answered by 2 years ago

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

local Name = "BOB"
print("Welcome to the game" .. Name)
Thank you so much Lifesaver! johnoscarbhv1 137 — 2y
That is called concatenation appxritixn 2235 — 2y
I knew it started with a c lol JustinWe12 723 — 2y
Log in to vote
Answered by
appxritixn 2235 Moderation Voter Community Moderator
2 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)


local Player = game.Players.LocalPlayer

local text = string.format("Hello, %s welcome to the game", Player.Name)
Thank you for your answer! johnoscarbhv1 137 — 2y

Answer this question