String manipulation

I’m running a gun shop GUI where the player clicks on the weapon and the detailed stats appear to the side. Problem is, I’m making 1 text label and trying to skip lines to include the stats quicker.
I have seen people using placeholders in strings to make it easier to write out but Ive never understood how it worked and the API on it is too complicated. Could anyone give me a quick example & explaining how I would make a string for a text label that will mention all the weapons stats and have a new line in between?

Here is the starting code I have:

function update(button)
	local gunStats = weaponStatsFolder[button.Name]
	gunText.Text = ("Pellet Damage: "..tostring(gunStats.Damage.Value))
end

Wanted text:
Pellet Damage: 10
Pellet Amount: 1
FireRate: 3

You can use “\n” in your script. For instance,

script.Parent.Text = 'Gun Damage: 888\nGun Fire Rate: 888'

\n creates a new line.

Ok and how would I use placeholders to replace the 888 and not fully type in

script.Parent.Text = "Gun Damage:"..toString(gunStats.Damage.Value)

I assume you’re talking about string.format?

script.Parent.Text = string.format([[
Pellet Damage: %d
Pellet Amount: %d
FireRate: %d
]], gunStats.Damage.Value, gunStats.Amount.Value, gunStats.Rate.Value) -- Insert the directories to the numerial values
-- You can use multi-line strings for better readability
1 Like

Yep, this should work just fine.

Yes this is exactly what I meant, tysm

This is the script:

	gunText.Text = string.format([[
%d 
%d TOTAL DAMAGE
%d FIRERATE
%d ROUNDS
]], gunStats.Type.Value, gunStats.Damage.Value, gunStats.FireRate.Value, gunStats.Ammo.Value)

Yet theres an error output asking for a number input:
invalid argument #2 to 'format' (number expected, got string)

EDIT: all values are stringValues

Change %d to %s; the former is for digits and the latter is for strings

Ohh ok thank you, I get it now