Help understand previous devforum post

Hi I need help understanding one part in this code in a devforum post I saw
basicaly all the code does is it makes a gui’s text the name of the song
code:

while wait() do

local marketplaceservice = game:GetService("MarketplaceService")

local sound = game.Workspace.Sound1

local songid = sound.SoundId:match("%d+")

script.Parent.Text = marketplaceservice:GetProductInfo(songid,Enum.InfoType.Asset).Name

end

the line I don’t understand is:

local songid = sound.SoundId:match("%d+")

what does

("%d+")

this mean? And what is it supposed to do?

1 Like

There: Strings | Documentation - Roblox Creator Hub

I wish it helps you!

1 Like

string.match is a function of the string class/library, which basically checks a given string for a string pattern or sequence of characters, and if it finds it, returns it from the string.

In this case, the %d pattern is used, which is for numbers. The + means means it’ll return all numbers found (something like that, I’d have to read up on that a bit.)

So I’m sure you could start to see how this would work. A string is given, and is converted to the song ID that will be used to get the info for it, by grabbing all the numbers out of the string.

1 Like