Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
0

How do I stop all other audio in the game and play the audio selected by the player?

Asked by 4 years ago

Hello. I'm very new to Roblox game development and Lua in general, and have no idea how to go about this. (I've tried the documentation to no avail.)

I have buttons on a SurfaceGui that, when clicked, each fire a script with this block inside of them:

function leftClick()
    workspace.Music.OldTown:Play()
end



script.Parent.MouseButton1Click:Connect(leftClick)

(each button has a different song playing when clicked.)

Currently, the audio stacks when multiple buttons are pressed. I do not want this.

I want to try and make stopping the previous sounds seamless, i.e being able to click a button, play the song, and then if the player clicks another button for another song the previous song audio stops and the new audio starts playing without the need of a "stop all sounds" button that is separate from the regular buttons.

If you can help or need more details/code examples, please reply. Thanks.

0
Wherever you're putting your sounds, you want to destroy the one that currently exists and replace it with a new sound with the ID the player requested to play. DeceptiveCaster 3761 — 4y

Answer this question