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

This script works in studio, but not in-game?

Asked by 9 years ago
SongOneId = 181547615
SongTwoId = 143959455
SongThreeId = 191819419
SongFourId = 131149175
SongFiveId = 151667588
SongSixId = 165719962
SongSevenId = 192805609
SongEightId = 252872782
SongNineId = 196183054
SongTenId = 210232032

Model = script.Parent
Music = Model.Music

while wait() do
    -- Song One (start)--------------------------------------
    Music.SoundId = "http://roblox.com/asset/?id="..SongOneId
    Music:Play()
    wait(Music.TimeLength)
    -- Song One (end)
    -- Song Two (start)--------------------------------------
    Music.SoundId = "http://roblox.com/asset/?id="..SongTwoId
    Music:Play()
    wait(Music.TimeLength)
    -- Song Two (end)
    -- Song Three (start)------------------------------------
    Music.SoundId = "http://roblox.com/asset/?id="..SongThreeId
    Music:Play()
    wait(Music.TimeLength)
    -- Song Three (end)--------------------------------------
    -- Song Four (start)-------------------------------------
    Music.SoundId = "http://roblox.com/asset/?id="..SongFourId
    Music:Play()
    wait(Music.TimeLength)
    -- Song Four (end)---------------------------------------
    -- Song Five (start)-------------------------------------
    Music.SoundId = "http://roblox.com/asset/?id="..SongFiveId
    Music:Play()
    wait(Music.TimeLength)
    -- Song Five (end)---------------------------------------
    -- Song Six (start)--------------------------------------
    Music.SoundId = "http://roblox.com/asset/?id="..SongSixId
    Music:Play()
    wait(Music.TimeLength)
    -- Song Six (end)----------------------------------------
    -- Song Seven (start)------------------------------------
    Music.SoundId = "http://roblox.com/asset/?id="..SongSevenId
    Music:Play()
    wait(Music.TimeLength)
    -- Song Seven (end)--------------------------------------
    -- Song Eight (start)------------------------------------
    Music.SoundId = "http://roblox.com/asset/?id="..SongEightId
    Music:Play()
    wait(Music.TimeLength)
    -- Song Eight (end)--------------------------------------
    -- Song Nine (start)-------------------------------------
    Music.SoundId = "http://roblox.com/asset/?id="..SongNineId
    Music:Play()
    wait(Music.TimeLength)
    -- Song Nine (end)---------------------------------------
    -- Song Ten(start)---------------------------------------
    Music.SoundId = "http://roblox.com/asset/?id="..SongTenId
    Music:Play()
    wait(Music.TimeLength)
    -- Song Ten (end)----------------------------------------
end 

In studio, it cycles through the songs as it's supposed to, but when I go to play the game on the ROBLOX website, all of the songs play at once, and for just about a second.

0
Is this a Script or a LocalScript? BlueTaslem 18071 — 9y
0
Regular script SchonATL 15 — 9y
0
I just tried it as a LocalScript and now it doesn't play at all. SchonATL 15 — 9y
0
Do note (Thanks to GoulStem) sometimes the script will run before the player loads, That's when `WaitForChild` comes in, Do try it. woodengop 1134 — 9y

1 answer

Log in to vote
2
Answered by
Redbullusa 1580 Moderation Voter
9 years ago

What is the purpose of this script? Do you want to put this globally, like in a boombox? Or do you want to play this locally?

If you want to play this globally, where everybody can hear it, keep your script, but shorten it with a "for" loop and a table.

SongTable = {181547615, 143959455, 191819419, 131149175, 151667588, 165719962, 192805609, 252872782, 196183054, 210232032}

Model = script.Parent
Music = Model:WaitForChild("Music")
-- Even though it will load before the server script run, this method is there just in case

while wait() do
    for i, SongID in pairs(SongTable) do
        Music.SoundId = "http://www.roblox.com/asset/?id=" .. SongID
        repeat
            wait()
        until Music.TimeLength > 0
        --[[

        I printed out the TimeLength in the server before I implemented the
        "repeat" loop, and it turns out that the TimeLength is 0. Could be
        because the script is running way too fast to let the Sound object
        read the length of the audio file.

        --]]
        Music:Play()
        wait(Music.TimeLength)
        Music:Stop() -- Why not?
    end
end

Else put the Sound in the local script and parent it to StarterGui.

SongTable = {181547615, 143959455, 191819419, 131149175, 151667588, 165719962, 192805609, 252872782, 196183054, 210232032}

Music = script:WaitForChild("Music")

while wait() do
    for i, SongID in pairs(SongTable) do
        Music.SoundId = "http://www.roblox.com/asset/?id=" .. SongID
        repeat
            wait()
        until Music.TimeLength > 0
        Music:Play()
        wait(Music.TimeLength)
        Music:Stop()
    end
end
0
not that it matters, but it bugs me. Use tostring(SongID). FutureWebsiteOwner 270 — 9y
Ad

Answer this question