How would I get the asset ID instead of the link?

I searched the internet and the DevForum but couldn’t find any great results.

I have a code that basically gets the name from an asset from an ASSETID. Problem when I get an assetID, it gets this rbxassetid://5410082171. I want it to get only 5410082171 How would I do that?

local musicPlayer = game.Workspace.Music.MusicPlayer

script.Parent.MouseButton1Click:Connect(function()
	print(musicPlayer.SoundId)
	local Asset = game:GetService("MarketplaceService"):GetProductInfo(musicPlayer.SoundId)
	script.Parent.Parent.SongName.Text = tonumber(Asset.Name)
end)

All is appreciated.

You can use :gsub

local text = "rbxassetid://5410082171"
text = text:gsub("rbxassetid://", "")
print(text) --5410082171
1 Like

You can use :gsub (the way @CharranCZ mentioned).
Or you can use :match

Example:

local assetId = "rbxassetid://5410082171"
local numbers = assetId:match("%d+")
print(numbers) -- 5410082171

Basically, the method I gave only gets number from the string.