Boombox surround sound system

hi! i am a new “developer” who has no idea what they are doing. i am going to be blunt, i just want to create an “obby” that is very personalized, relaxed, and fun. i refuse to use free models and instead am just going to try to make whatever i can, and draw the rest as decals. what i want to do here is have a local sound system, or an area in which the music plays near the player. the further they are, the less they can hear it. until some point the music just can’t be heard at all.

some extras if it can be done, i want the boombox to bounce/animate a little while it plays. i want users to be able to interact with it via holding down on their screen or holding on e (with pc) to change to a preset select song ids.

the main goal is just to make a “surround sound” where you can chill by the boombox! if someone knows how to do this, please let me know, and explain it to me or point me to a video. i would love to actually know what i am doing, because all of the videos i’ve looked up just point me to using the boombox item or setting up a ui system that is individual to the users screen to play their own id music


edit : i found out how to add music and a texture to come out of it using particle effect, now my question is how do i change the song to have a few tracks? (sorry for no sound, but its the " Life in an Elevator" song, my computer just can’t pick up any sound from games. its a macbook

1 Like

Hello and welcome, Fellow Dev!
In order to make a sound play, and have its volume lower the further away you are, simply add a “Sound” instance to any of your parts, establish the SoundId you want, and set the property “Playing” and “Looping” as you wish.

In order to set how far the sound should play, you should change the properties: “RollOffMaxDistance” and “RollOffMinDistance”
Here is what each means:

  • RollOffMaxDistance:
    The maximum distance, in studs, a listener can be from the sound’s origin and still hear it.

  • RollOffMinDistance:
    The minimum distance, in studs, at which a Sound instance will begin to attenuate (decrease in volume).

In order to achieve a consistent “fade out” effect as you get further away from the boombox, you will want to establish its “RollOffMode” as well. The RollOffMode is a property inside the sound instance that establishes how the volume of a sound is supposed to attenuate (fade out). In order to make the fade gradual, you should choose a RollOffMode such as “LinearSquare”

About the boombox animating, you should find interest in researching about TweenService, which allows you to gradually change values, including the size of parts.
On allowing users to interact with the boombox, you can add a ClickDetector, or a ProximityPrompt to a Part, and configure any action when they are triggered by using a Script. Here is a short example:

local ProximityPrompt = script.Parent.ProximityPrompt

local function TriggerPrompt()
	print("Hello!")
end

ProximityPrompt.Triggered:Connect(TriggerPrompt)

Thank you for participating in the Dev Forum!

2 Likes

Regarding your edit to the topic:
You will find an easy solution to change which sound is playing by using the ProximityPrompt as I have demonstrated! I will add to my previous code to demonstrate.
You may achieve the desired effect, either by changing the soundId:

local ProximityPrompt = script.Parent.ProximityPrompt

local function TriggerPrompt()
	script.Parent.Menu.SoundId = "rbxassetid://1234567890"
end

ProximityPrompt.Triggered:Connect(TriggerPrompt)

Or by changing which sound instance it is playing at that moment:

local ProximityPrompt = script.Parent.ProximityPrompt

local sound1 = script.Parent.sound1
local sound2 = script.Parent.sound2

local function TriggerPrompt()
	if sound1.Playing then
		sound1:Stop()
		sound2:Play()
	elseif sound2.Playing then
		sound2:Stop()
		sound1:Play()
	end
end

ProximityPrompt.Triggered:Connect(TriggerPrompt)

Feel free to follow up with any questions. Anything you code inside the function connected to the ProximityPrompt’s trigger will run once any player triggers the ProximityPrompt, as long as it has been established in a ServerScript (The default, gray colored scripts).
Keep in mind that in the example provided above, the two conditions only run if one of the two songs are playing, if neither are, then nothing happens, but you can add a condition for that too!

If instead of this, what you actually want, is for a list of songs to be played automatically instead of just one, you could achieve that with code such as this:

local sound1 = script.Parent.sound1
local sound2 = script.Parent.sound2

while true do -- Using "while true do" results in an infinite loop. Using this without pauses or delays, such as task.wait, may crash studio due to excessive processing.
	sound1.Ended:Wait() -- This code assumes sound1 is already playing when the game starts.
	sound2:Play()
	sound2.Ended:Wait() -- Regarding crashes mentioned, this code waits until a sound has ended to continue running, and therefore should be fine.
	sound1:Play()
end

Remember, in this final example, you might want to use sound:Stop() if you set the “looped” property to enabled in any of the two sound instances, or disable the looped property completely, otherwise they may play overlapping!
Godspeed, Fellow Dev!

1 Like

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.