Play Sounds in a Part over a GUI

Hello!

Ok, so: I want to make a GUI
The GUI is a SoundID-Player, which makes a sound/music play when you press “Play” and stops when pressing “Stop”
And I can’t get it to work, and sorry for my bad english, it isn’t my primary language :crossed_fingers:

1 Like

What do you mean by that, I read it a couple times and still don’t know what you are trying to say.

Ok, so: I want to make a GUI
The GUI is a SoundID-Player, which makes a sound/music play when you press “Play” and stops when pressing “Stop”
And I can’t get it to work

Ok, so when you have the buttons ready, add a local script, which has Play as it’s parent.

script.Parent.MouseButton1Click:Connect(function()
    game.Workspace.Sound:Play()
end)

Then, add a local script to the Stop button.

script.Parent.MouseButton1Click:Connect(function()
    if game.Workspace.Sound.Playing == true then
    game.Workspace.Sound:Pause() -- you can also resume the sound for this, but if you want it to restart then the player presses play again, just change this line with this: game.Workspace.Sound:Stop()
end)
2 Likes
local Song = script.Parent.Song --Whatever you're using
local PlayGui = script.Parent.PlayGui --the Play button
local StopGui = script.Parent.StopGui --the Stop button
PlayGui.MouseButton1Click:Connect(function()
    Song:Play()
end
StopGui.MouseButton1Click:Connect(function()
   Song:Stop() --I forgot the function for stopping a sound
end
1 Like

Thanks for the help, but one problem: I want players to hear the music too. So idk if I can use a LocalScript

Now another problem: How do I tell a Sound what SoundID it has?

Do I use Sound.SoundID = “”?

Yes, Sound.SoundID is a property of sound which tells you which Audio is being played.

1 Like

You could just send a remote event to the server when the button has been clicked and then the server will listen to the event and it can be able to play the sound making every player to hear it.

1 Like

And how do I do that? I’ve never used RemoteEvents before :sweat_smile:

We know that there is a server and a client. The server controls every player and the client only controls a specific player. If you created a part on the server then everyone can see it, if you create a part on the client then that part will only be seen by the player.

We use remote events when we want to interact with the server and the client.

There are 3 functions that we use to send an event to the server or client:

FireServer()
FireClient()
FireAllClients()

and theres 2 events that we use:

OnServerEvent
OnClientEvent

So in this context, we want to click on a button and play it for everyone else as you said, so let’s put this into practice:

Local Script

script.Parent.MouseButton1Click:Connect(function()

RemoteEvent:FireServer()

end)

Server


RemoteEvent.OnServerEvent:Connect(function()

      Sound:Play() -- plays for every player

end)

You can read this article too: Custom Events and Callbacks | Documentation - Roblox Creator Hub

1 Like

Thank you! That helped alot, I’ll have a look into it. I’ll mark your reply as the solution If it works like I wanted it to work

You don’t have to use RemoteEvents to play sounds on every client. Sounds are automatically replicated, and if you want to play a sound only for a client, use SoundService
More simply, it’ll already play for other people and requires no more action.

1 Like

“Sound playback is not filtered. If a particular client starts playing a sound, all of the other clients will also play it unless SoundService.RespectFilteringEnabled is set to true.” - Sound | Documentation - Roblox Creator Hub

You are correct. Though, @fabian411HD, you may want to disable the “RespectFilteringEnabled” property on game.SoundService. For the sound, played by a LocalScript, to normally replicate to everyone.

2 Likes

Here i think this is what your looking for
(Also put a RemoteEvent in ReplicatedStorage called ToggleMusic and A sound in Workspace called Music)
Client (localscript):

script.Parent.Stop.MouseButton1Click:Connect(function()
game.ReplicatedStorage.ToggleMusic:FireServer()
end)
script.Parent.Start.MouseButton1Click:Connect(function()
game.ReplicatedStorage.ToggleMusic:FireServer()
end)

Server (serverscript):

local IsPlaying = false
local ShouldRestart = true -- Change this to should it restart when turned back on
game.ReplicatedStorage.ToggleMusic.OnServerEvent:Connect(function()
    if IsPlaying == true then
         if ShouldRestart == false then
           game.Workspace.Music:Pause()
         else
           game.Workspace.Music:Stop()
         end
    else
           game.Workspace.Music:Play()
    end
end)
1 Like

Where do I put the Serverscript tho?

game.ServerScriptService is where to put it I am making a uncopylocked game for you also with the same thing

1 Like

Thank you, that’ll defo help me understand this better, lmao

Oh and sorry i made a mistake in the code i gave you, Here is the game with it fixed: music player - Roblox (made on my other account)

It also plays for other players. Its done by server.