This is what i tried but it work work:
local SoundId = script.Parent.Sound.SoundId
local Asset = game:GetService("MarketplaceService"):GetProductInfo(SoundId)
print(Asset.Name)
You’re correct on the GetProductInfo, however; you’ve forgotten about the SoundId property having “rbxassetid://” infront of the id. (keep in mind that this solution will not work if your soundId looks something like www.roblox.com/asset/?id=1231231
.
You’re essentially doing game:GetService("MarketplaceService"):GetProductInfo("rbxassetid://12312312").Name
.
Simply get rid of the rbxassetid:// using string.split, and then convert it to int64.
local SoundId = tonumber(string.split(script.Parent.Sound.SoundId, "rbxassetid://")[2])
This is correct, but string.split
is not an appropriate way of doing that, you could simply string.gsub
to get rid of the part you don’t need by replacing it with ""
.
local SoundId = tonumber(string.gsub(script.Parent.Sound.SoundId, "rbxassetid://", ""))
i get this error
14:28:54.589 - Players.zubair127.PlayerGui.MusicSystem.LocalScript:2: invalid argument #2 (base out of range)
Sorry I forgot string.gsub()
returns two values, you would need to use select()
to grab only the first one.
local SoundId = tonumber(select(1 ,string.gsub(script.Parent.Sound.SoundId, "rbxassetid://", "")))
select()
selects a certain value from a “tuple”.
local function f()
return "hi", "bye", "hello"
end
print(select(2, f())) --"bye"
still same error here’s my code:
local SoundId = tonumber(select(1 ,string.gsub(script.Parent.Sound.SoundId, "rbxassetid://", "")))
local Asset = game:GetService("MarketplaceService"):GetProductInfo(SoundId) --[[Get's Product Information Of The Sound--]]
print(Asset.Name) --Print's The Name Of The Audio
Your probably best solution to filter the ID of a content URL is pattern matching:
id = content_url:match("%d+")
Where %d
takes any digit, +
takes any positive amount of the preceding value and :match
returns the matched part of the given string.
Using this, it doesn’t matter whether you use rbxassetid://
or https://www.roblox.com/asset/?id=
either.
so how do i use that in my code?
local id = Sound.SoundId:match("%d+")
local Asset = game:GetService("MarketplaceService"):GetProductInfo(id)
thanks mate 30 characters…