Get AssetID from Table

Hi all, I’m trying to script a Music System with a UI Controller to control all the features and skip music and all sorts. However, I’ve ended up in a bit of trouble.

What I’m trying to do is, get the asset id from the table’s title. I will show you what i mean by providing both scripts below.

[1841647093] = { --# trying to get this id here

				["SongName"] = "default", --# Set to "default" to use the name uploaded to Roblox.
				["Image"] = "default" --# Set to "default" to use your default album art.

			}
local AssetID = Configuration.Songs[math.random(Module.Songs.NumberOfSongs,#Configuration.Songs)]
										local currentSong = MarketplaceService:GetProductInfo(AssetID, Enum.InfoType.Asset)
										
				

										for _,S in pairs(Speakers) do
											if S.Identification.Value == "MeshSpeaker" then
												S.Speaker.Sound.SoundId = "rbxassetid://"..AssetID
												UI.Homepage.currentsong.Songname.Text = currentSong.Name
												UI.Homepage.currentsong.Songartist.Text = currentSong.Creator
												S.Speaker.Sound:Play()
											end
										end

I’m new to things like this and I’ve looked on the Documentation but I don’t really understand it.

Wouldnt it be easier to make a table within the same script then get the random id from it:

local Songs = {
[1841647093] = { 
				["SongName"] = "default", --# Set to "default" to use the name uploaded to Roblox.
				["Image"] = "default" --# Set to "default" to use your default album art.
			}
}

local AssetID = Songs[math.random(1, #Songs)]

local currentSong = MarketplaceService:GetProductInfo(AssetID, Enum.InfoType.Asset)
for _,S in pairs(Speakers) do
if S.Identification.Value == "MeshSpeaker" then
S.Speaker.Sound.SoundId = "rbxassetid://"..AssetID
UI.Homepage.currentsong.Songname.Text = currentSong.Name
UI.Homepage.currentsong.Songartist.Text = currentSong.Creator
S.Speaker.Sound:Play()
end
end

I have it in a seperate modulescript so I can have different config options in there as well, I will be selling this system for Robux anyway, therefore I don’t want people having access to my source code.

image
I’ve tried table.find but I had no luck either, what if I change the id into “ID” or ‘ID’ would that work?

What if you put id as part of the information instead of table

local Songs = {
	[1] = {
		["SongId"] = 325151,
		["SongName"] = "default",
		["Image"] = "default"
	},
	[2] = {
		["SongId"] = 8565151,
		["SongName"] = "default",
		["Image"] = "default"
	},
	[3] = {
		["SongId"] = 65211,
		["SongName"] = "default",
		["Image"] = "default"
	},
}

Can you check if that work

And add .SongId

local currentSong = MarketplaceService:GetProductInfo(AssetID.SongId, Enum.InfoType.Asset)
S.Speaker.Sound.SoundId = "rbxassetid://"..AssetID.SongId

Works, thank you for your help.

1 Like

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.