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

Trying to make area specific music script..?

Asked by
Kriptoh 10
9 years ago

So, here's my problem: I want to make a club in one of my games that plays music in ONLY the club (Area specific music) but, while the script DOES work in playing the music and keeping it in one area, for some reason it plays multiple songs at once. Help?

Here's the script:

sounds = {144498225, 144586529, 142401311, 145068500}

for _, audio in pairs(sounds) do
     game:GetService("ContentProvider"):Preload("http://www.roblox.com/asset/?id=" .. audio)
end

for _, audio in pairs(sounds) do

for i = 1, #sounds do
    local music = Instance.new("Sound", workspace.clubMusic) 
    music.Name = sounds[i]
    music.SoundId = "http://www.roblox.com/asset/?id=" .. sounds[i]
    music:Play()
    print("Waiting: ".. music.TimeLength)
    wait(music.TimeLength)
    music:Destroy()
end
end
0
Replace line 7 with "while true do", because you're going to iterate the second "for" loop only 4 times, which means the 4 songs will only be played 4 times. Redbullusa 1580 — 9y
0
Thanks, but it still has the problem where it plays multiple songs at once Kriptoh 10 — 9y

1 answer

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

Try to add debounce in the "for" loop.

SoundAssets = {144498225, 144586529, 142401311, 145068500}

ContentProvider = game:GetService("ContentProvider")

IsPlaying = false

while ContentProvider.RequestQueueSize < 0 do
    for _, audio in pairs(SoundAssets) do
        ContentProvider:Preload("http://www.roblox.com/asset/?id=" .. audio)
        wait()
    end
end

while true do
    for _, audio in pairs(SoundAssets) do
        if not IsPlaying then
            IsPlaying = true
            local Sound = Instance.new("Sound", workspace.clubMusic)
            Sound.SoundId = "http://www.roblox.com/asset/?id=" .. audio
            print("Waiting: " .. Sound.TimeLength)
            Sound:Play()
            wait(Sound.TimeLength)
            Sound:Destroy()
            IsPlaying = false
        end
    end
end
0
Thank you! Kriptoh 10 — 9y
Ad

Answer this question