Hello,
My goal is to allow players to act as DJs in the game and work at an in-game radio station to decide which songs will be broadcast throughout the game to players. For simplicity, I have started with just trying to get an automated playlist to broadcast throughout the game. I would like the same music to be playing on all players computers, but I would like them to not hear that music unless they toggle on the radio option (and this option should only make the music audible for that player who clicked it).
I most recently tried placing the songs inside of a Sound Group within the StarterGui and then having a remote event fire to all clients that triggers the playing of the sound but with the volume set to 0. I then have a GUI with a localscript button that toggles the volume on and off. This would work sometimes, but at other times when I would load the game in studio it would end up playing some or all of the songs at the same time immediately (before I selected the radio option).
The code is simple and it is just a loop that randomly generates a number within the range of songs that exist, detects the sound ID’s length, plays that sound and unmutes it, waits the sound ID’s length time, re-mutes that sound and then moves onto the next sound.
NOTE: by default the below bool value is set to true this is just a placeholder so I can allow people to manually change the songs in the future
Here is the code:
while game.Workspace.RadioStationData.Automatic.Value == true do
local num = math.random(1,23) --last number must be the amount of songs in the folder
local sound = “Sound”…num
local songLength = game.StarterGui.MusicRadio[sound].TimeLength
game.ReplicatedStorage.RemoteEvents.PlayMusicRadio:FireAllClients(sound, songLength)
wait(songLength + 1)
end
A lesser issue is that I hear a “click” or “pop” whenever I stop playing the game in studio (which sounds like it is cutting off the audio abruptly when it quits the game, however this occurs when all of the audio sources are muted on the client.)
I have tried searching for assistance with this, but I was not able to find anything.
Thank you all very, very much!