Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
1

How Can I Pull Data From Dictionary?

Asked by 3 years ago

I have already looked on the Roblox Wiki and stuff but I couldn't find out how to do this but I am making a music player and want custom song titles, artist names, and album art but whenever I try and pull data from my dictionary, it doesn't seem to grab any data at all. There are no errors in the output.

--Variables
local Players = game.Players
local Player = Players.LocalPlayer
local Sound = script.Parent.Music
local GUI = Player.PlayerGui.MusicGui

local ArtGUI = GUI.RadioGUI.Art.AlbumArt
local TitleGUI = GUI.RadioGUI.Info.Title
local ArtistGUI = GUI.RadioGUI.Info.Artist

SongList = {

    {
        ID = 7029024726,
        Title = "Bloom",
        Artist = "Throttle",
        ArtID = 7377998210
    },
    {
        ID = 7024154355,
        Title = "Feels Like Love",
        Artist = "Laszlo",
        ArtID = 7378871754
    },
    {
        ID = 1061409802,
        Title = "Kodokushi",
        Artist = "Kyoto Black, Mihka!",
        ArtID = 7378895447
    },
    {
        ID = 2409526081,
        Title = "Only Way Out (Blyzo remix)",
        Artist = "Madeon , Blyzo",
        ArtID = 7378912620
    },

} --end song list

while wait() do

    Sound:Stop()

    if not Sound.IsPlaying then

        local SongChosen = SongList[math.random(1,#SongList)]
        Sound.SoundId = "rbxassetid://"..SongChosen["ID"]
        TitleGUI.Text = SongChosen["Title"]
        ArtistGUI.Text = SongChosen["Artist"]
        ArtGUI.Image = "rbxassetid://"..SongChosen["ArtID"]
        Sound:Play()
        wait(Sound.TimeLength)

    end

end

1 answer

Log in to vote
0
Answered by
TGazza 1336 Moderation Voter
3 years ago

Looks like your songs are not loading due to your while wait() do loop.

while wait() do

    Sound:Stop()

    if not Sound.IsPlaying then

        local SongChosen = SongList[math.random(1,#SongList)]
        Sound.SoundId = "rbxassetid://"..SongChosen["ID"]
        TitleGUI.Text = SongChosen["Title"]
        ArtistGUI.Text = SongChosen["Artist"]
        ArtGUI.Image = "rbxassetid://"..SongChosen["ArtID"]
        Sound:Play()

        wait(Sound.TimeLength)

    end

end

This works fine for people that have had time for the songs to download but not for anyone new where it would simply skip to the next song. Which will also not have enough time to load causing nothing to play.

To get round this i would add one little check: while Sound.IsLoaded == false do wait()end -- wait for things to load!

This would wait for the sound to load before continuing onto the next song. Beware!: this might still break if you get the SongID wrong or the Song isn't available or simply deleted!.

While wait do loop in full:

while wait() do

    Sound:Stop()

    if not Sound.IsPlaying then

        local SongChosen = SongList[math.random(1,#SongList)]
        Sound.SoundId = "rbxassetid://"..SongChosen["ID"]
        TitleGUI.Text = SongChosen["Title"]
        ArtistGUI.Text = SongChosen["Artist"]
        ArtGUI.Image = "rbxassetid://"..SongChosen["ArtID"]
        Sound:Play()

        while Sound.IsLoaded == false do wait()end -- wait for things to load!

        wait(Sound.TimeLength)

    end

end

Hope this helps!

p.s sorry for the bad grammar as I'm operating on very little sleep lol >_>

0
Unfortunately this didn't work... I made sure all the sound ids were valid and working and still no fix. I have a feeling it could be that its a table within a table and that I'm grabbing something not valid but I wouldn't know how to have a work around for that because I havent seen any info on it. raffkaisa 12 — 3y
0
i've given you mail on roblox :) TGazza 1336 — 3y
Ad

Answer this question