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.