Help with making a sound region with a playlist

I want to make a sound region, so I made a block with a sound on it first, and that worked. So I put this script for a playlist on the block but it does not work. Can someone help explain why it does not work or if there is a better method to put a playlist on a sound part?

local Sound1 = game.Workspace.Sound.Sound1
local Sound2 = game.Workspace.Sound.Sound2
local Sound3 = game.Workspace.Sound.Sound3
local Sound4 = game.Workspace.Sound.Sound4
local Sound5 = game.Workspace.Sound.Sound5
local Sound6 = game.Workspace.Sound.Sound6
local Sound7 = game.Workspace.Sound.Sound7
local Sound8 = game.Workspace.Sound.Sound8
local Sound9 = game.Workspace.Sound.Sound9
local Sound10 = game.Workspace.Sound.Sound10
---------------------------------------------
while true do
	Sound1:Play()
	Sound1.Ended:Wait()
	wait(5)
	Sound2:Play()
	Sound2.Ended:Wait()
	wait(5)
	Sound3:Play()
	Sound3.Ended:Wait()
	wait(5)
	Sound4:Play()
	Sound4.Ended:Wait()
	wait(5)
	Sound5:Play()
	Sound5.Ended:Wait()
	wait(5)
	Sound6:Play()
	Sound6.Ended:Wait()
	wait(5)
	Sound7:Play()
	Sound7.Ended:Wait()
	wait(5)
	Sound8:Play()
	Sound8.Ended:Wait()
	wait(5)
	Sound9:Play()
	Sound9.Ended:Wait()
	wait(5)
	Sound10:Play()
	Sound10.Ended:Wait()
	wait(5)
end

What exactly isn’t working? Is there a certain sound that’s not playing correctly?

I’m not sure if your code is broken, but supposedly my version is a bit better and should work more stable, although it’s not perfect. Try also to check your part names, sounds and etc.

local Sound = game.Workspace:FindFirstChild("Sound") or game.Workspace:WaitForChild("Sound")
local Sounds = Sound:GetChildren()
local CurrentIndex = 1

local Waiting = 5

if Sounds ~= nil and #Sounds > 0 then
	for index, instance in ipairs(Sounds) do
		if not instance:IsA("Sound") then
			table.remove(Sounds, index)
		end
	end
end

local function PlaySound(sound: Sound)
	sound:Play()
	sound.Ended:Wait()
	wait(Waiting)
end

local function PlayNext()
	if #Sounds == 0 then
		return
	end
	
	if Sounds[CurrentIndex]:IsA("Sound") then
		PlaySound(Sounds[CurrentIndex])
		
		CurrentIndex += 1
		
		if CurrentIndex > #Sounds then
			CurrentIndex = 1
		end
	end
end

while true do
	PlayNext()
	wait(0.1)
end

I would recommend have either a table of SoundIds, or a folder with Sound objects (If you want to easily change properties like Volume, PlaybackSpeed, etc).

This way you dont have increasingly long, hard to maintain code, when you might need to add more sounds. I have written this code on the forum and haven’t tested, so let me know if it doesn’t work for you.

local ReplicatedStorage = game:GetService("ReplicatedStorage")
local Sounds = ReplicatedStorage.Sounds -- Change this to the folder where your sounds are stored

while true do -- You may want to create a new thread for this, or any code below will yield
	for _,sound in Sounds:GetChildren() do
        sound:Play()
        sound.Ended:Wait()
        task.wait(5)
    end
end

Ok so this works for making the sounds play, thank you. If I wanted to make this work like a sound region, can I just simply add

Sound.RollOffMinDistance = 10
Sound.RollOffMaxDistance = 20
Sound.RollOffMode = "Linear"

to the beginning?

1 Like

I’m not sure what you mean, but I hope I understood you correctly. If you need to do it exactly in my code, you can dynamically set the region in the PlaySound function before you play it (for example: sound.RollOffMaxDistance = 5, etc). If you don’t need to change the region dynamically at all, just set static values for these sounds.

Ok I’ve done that, but it still doesn’t do what I wanted it to. I realize I was unclear before of my exact goal, so I will reexplain it. I want to create a playlist that works inside a sound region, and while the script you wrote before works to play the music, editing the sound roll off doesn’t seem to have any effect on whether or not the sound can be heard in other regions. I frankly have no idea why that is so, or what should be done to remedy that.