local MarketPlaceService = game:GetService("MarketplaceService")
local SongLabel = script.Parent.SongLabel
local SkipButton = script.Parent.SkipButton
local MuteButton = script.Parent.MuteButton
wait(1)
while true do
local Sounds = script:GetChildren()
local RandomIndex = math.random(1,#Sounds)
local RandomSound = Sounds[RandomIndex]
local id = RandomSound.SoundId
local SongInfo = MarketPlaceService:GetProductInfo(id)
SongLabel.Text = SongInfo.Name
RandomSound:Play()
wait(RandomSound.TimeLength)
end
A Sound’s SoundId property is a string, hence why it includes “rbxassetid://…” or “https://roblox.com/…”, but GetProductInfo requires a number. You would have to get the number from the string using string patterns and then convert it to a number:
local SongInfo = MarketPlaceService:GetProductInfo(tonumber(id:match("%d+")))
I assume you’re trying to make a music player system that picks a random song and plays it? You’ve chosen quite an odd method to do this, you don’t need each sound instance if you have each songID already in a table, simply have 1 sound instance and edit that one.
local MarketPlaceService = game:GetService("MarketplaceService")
-- Don't comment this, the script will ignore it
local Songs = {
7029024726,
7023617400,
7023598688,
5410086218,
1838660362,
1847606521
}
local SongLabel = game.StarterGui.MusicGUI.Frame.SongLabel
--local SkipButton = script.Parent.SkipButton
--local MuteButton = script.Parent.MuteButton
local SoundObject = workspace.Sound -- [Create this]
wait(1)
while true do
-- local Sounds = script:GetChildren() [We don't need this anymore]
local RandomID = Songs[math.random(#Sounds)] -- Get a random song ID
local SongInfo = MarketPlaceService:GetProductInfo(RandomID)
SongLabel.Text = SongInfo.Name
SoundObject.SoundId = RandomID
SoundObject:Play()
task.wait(SoundObject.TimeLength) -- Since wait is deprecated, we'll use task.wait(
end
local MarketPlaceService = game:GetService("MarketplaceService")
local SongLabel = script.Parent.SongLabel
local SkipButton = script.Parent.SkipButton
local MuteButton = script.Parent.MuteButton
wait(1)
while true do
local Sounds = script:GetChildren()
local RandomIndex = math.random(1,#Sounds)
local RandomSound = Sounds[RandomIndex]
local id = string.match(RandomSound.SoundId, "%d+")
local SongInfo = MarketPlaceService:GetProductInfo(id)
SongLabel.Text = SongInfo.Name
RandomSound:Play()
wait(RandomSound.TimeLength)
end