I need help with how this works and what it is.
local Label = script.Parent.Label
Label.Text = ("Hello there, %s!"):format(player.Name)
What is, format?? And how does % work?
I need help with how this works and what it is.
local Label = script.Parent.Label
Label.Text = ("Hello there, %s!"):format(player.Name)
What is, format?? And how does % work?
Format is putting a string that can be formatted as accordingly to specifiers:
Since "Hello there, %s!"
, is a string and uses the %s
specifier for strings only. The string uses a function called format
. Arguments included will replace the %s
with whatever string that comes first.
Most of the time string.format is used to replace strings. I think something else can be done.
Instead of:
String1 .. String2
It can be used:
local String1 = "Hello, %s"
String1:format(String2)
Like what you did, the last part %s changes depending on what you will do.
It is very useful for very long strings.
local String = "Hello, I am %s and I have come to explain about %s!"
String:format("SOTR654","string.format")
local User, ToExplain = "SOTR654", "string.format"
local String = "Hello, I am " .. User .. " and I have come to explain about " .. ToExplain .. "!"