Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
✓ ANSWER ACCEPTED

Trying to make area specific music script..?

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

2 comments

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.

0

Thanks, but it still has the problem where it plays multiple songs at once

1 answer

✓ Accepted answer

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

1 comment

0

Thank you!

This discussion is preserved as it was. New answers, comments, and votes are closed.