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

I'm not sure why my music script isn't carrying on to the next song? [ANSWERED; FREE SCRIPT BELOW]

Asked by 5 years ago
Edited 5 years ago

I know this script would have lots of mistakes and would be complicated; it would be really appreciated if you could help me make it less sophisticated too. :)

local sound = script.Parent
songs = {
    id1 = 181927642;
    name1 = "Ariana Grande - Last Christmas";   
    id2 = 603146550;
    name2 = "Cartoon - On & On"
}
while next do
    local song = songs.id1 or songs.id2
    if song == string.sub(1,4)=="name" then 

    else
        sound.SoundId = "rbxassetid://"..math.abs(song)
        if song == songs.id1 then
            sound.Name = songs.name1
        elseif song == songs.id2 then
            sound.Name = songs.name2
        end
        sound:Play()
        if sound.IsPlaying == false then
            song = songs.id2 or songs.id1
        end
        repeat wait(1) until sound.TimePosition == sound.TimeLength
    end
end

2 answers

Log in to vote
0
Answered by 5 years ago
Edited 5 years ago

Well you have a really complicated code. And it can all come out to something really easy....

local sound = script.Parent
local songs = {"Song id's"}
local song = 1
local title = -- Put here where you text frame is

while true do
    wait(1)

    function setSong()

        local song = songs[Song]

        Song = Song + 1

        sound.SoundId = "rbxassetid://"..song

        if Song == #songs + 1 then
            Song = 1
        end

    end
    sound.SoundId = "Song Id here" then
        title.Text = --Name of song here inside these: " "
    end

    if not sound.IsPlaying then
        setSong()

        sound:Play()
    end
end

Then all songs in the songs table, will play in that playlist. And the playlist will repeat, when it's done. Hope that helped you. - Toby

0
Oh, I'm really grateful for you giving a script or me, but I was looking for a person who could fix my script. Thank you so much though! :D ISkyLordDoge 37 — 5y
0
I made a small change. There was a variable missing... tobiO0310 58 — 5y
0
Also accept this, if you don't need any help more. ;) tobiO0310 58 — 5y
0
I just remembered something! I was going to have a string saying the name on it... though, I'm sorry if this is drowning your time. ISkyLordDoge 37 — 5y
View all comments (2 more)
0
Try and look at the code now, I made it so that you can have a text frame for the title. tobiO0310 58 — 5y
0
Thanks! ISkyLordDoge 37 — 5y
Ad
Log in to vote
0
Answered by 5 years ago
Edited 5 years ago

Actually (I'm only editing this script to help others) I found an easier and efficient way to create it:

local Sound = script.Parent-- Create a variable to get your sound

songs = {
    1367367158,
    891225839,
}-- IDs go in here.
names = {
    "Kisma - Fingertips",
    "TheFatRat - Fly Away",
}-- Names go in here.

for i, v in ipairs(songs) do-- function
    Sound.SoundId = "rbxassetid://"..songs[i]-- Changes the song ID
    Sound.Name = names[i]-- Changes the song Name
    Sound:Play()-- Plays the music
repeat wait(1) until Sound.IsPlaying == false-- Waits until this music is finished to play next music
    if i == ((2)) then -- Put in the amount of songs you have in the double brackets 
        i = 1
    end
end

Hope it helps!

Answer this question