How to make a playlist of songs that sounds on a specific model

I am making a car, and I’d love to add a radio, I won’t use a radio system cause I only need 6 songs which I got ready.
What I am trying to achieve, is putting this sounds inside a radio model and not making them sound in the whole workspace. I’ve set the max distance you can hear the audio to 140, could that contribute to what am I looking for? I won’t understand if you guys tell me what should I do, I never scripted before.
So what I need:
Is a looped song playlist (6 Songs), which don’t sound on the entire workspace.
My grammar isn’t the best and I am sorry if I was unclear with what I need, if you have any doubts please answer me. And if you can get to help me send the whole script and instructions on how to add it, lol.

So are you saying for the sound that you don’t want everyone to hear it and only the player that activated the radio?

Well, I want to make it people can hear it but not on the entire workspace, only when u are near it. Like a boombox but instead the music plays automatic.

Ok I see now. What you could do for the playlist is this:

while true do -- Any events inside of the while true do will repeat forever until the server shutsdown
	workspace.BoomBox.SoundName:Play() -- This is the sound that we want to start playing first
	workspace.BoomBox.SoundName.Ended:Wait(3) -- When the song ends, we wait 3 seconds before the next song plays 
	workspace.BoomBox.Music:Play()
	workspace.BoomBox.Music.Ended:Wait(3)
	-- You can add more sounds if you would like
end

Let me know if this helps. :slight_smile:

Place the audio (instance) inside a part (not a model). Then set the RollOffMaxDistance to 140.

image

1 Like

If you only have 6 songs use the method that @Dogcraft_01 suggested, if you’re planning on adding more songs in the future try to use this:

local children = script.Parent -- Change this for the location of your songs
local Sounds = {}
local StartWith = 1 -- Start with song nº 1

for i, child in ipairs(children:GetChildren()) do -- Transfer songs to the array
	if child:IsA("Sound") then
		Sounds[#Sounds+1] = child
	end
end

function GetSong()
	Sounds[StartWith]:Play() -- Play the song
	print("Now Playing "..Sounds[StartWith].Name)
	Sounds[StartWith].Ended:Wait(1) -- Time to wait before the next song is played
	
    -- Select the net song to play --
	if #Sounds == StartWith then -- If is the last song on the array then
		StartWith = 1 -- Go to the first song
	else -- If is not the last song on the array
		StartWith += 1 -- Next Song
	end
    -- End --
	
	GetSong() -- Play the next song
end

GetSong() -- Function to fire
1 Like

If you wish to loop through the playlist and not randomize the songs than use the following script:

local TimeBetweenSongs = 1 -- Extra time we'll wait before playing the next song.
local Playlist = { -- Music Ids of the songs we'll play
    123456,
    1234567,
    123457,
    654321, 
-- If you want to add more sound ids then put the id here and end it with a comma.
}
local Sound = script.Parent.Audio -- Path to the audio instance

local function nextSong(id) -- Every time "nextSong()" is called this will fire. 
    -- If the parameter "id" is invalid this will break.
    Sound.SoundId = id
    Sound:Play()
    Sound.Ended:Wait(TimeBetweenSongs)
end

while true do 
    -- Anything inside of this will repeat for ever.
    for _,musicId in pairs(Playlist) do -- Loops through the playlist
        nextSong(musicId)
    end
end
-- Anything after this will never have the chance to fire.

Hello, I know it’s late but when i use your script the first song plays fine, and then the second song doesn’t play at all.

Should it be in a Local or Server script??