Music Gui does not play for everyone but only plays for me

Hey everyone! So I put together a Music Gui that basically is like a music control, it works fine and functions well but it only plays for me, and I wanted to know how I can make it so that it plays for everyone in the server!

Here’s the script (It’s a local script and I tried changing it to a normal script but doing that made it not play in the first place even for me):

local frame = script.Parent

local scrFrame = frame.ScrollingFrame

local music = frame.Music

local current = frame.Current

local volumeBar = frame.VolumeBar.VolumeGreen

local volumeUp = frame.VolumeUp

local volumeDown = frame.VolumeDown

local musicButton = frame.Parent.MusicButton

local stop = frame.Stop

local playing



frame.Visible = false



current.Text = "Currently Playing:"



local function playMusic(sound)

	if playing then

		playing:Stop()

	end



	sound:Play()

	playing = sound

	playing.Volume =  tonumber(volumeBar.Text) / 100



end



volumeUp.MouseButton1Click:Connect(function()

	if playing then

		if playing.Volume < 1 then

			playing.Volume += 0.1

		end

		volumeBar.Size = UDim2.new(playing.Volume, 0, 1, 0)

		volumeBar.Text = math.floor(playing.Volume * 100 + 0.5)

	end

end)



volumeDown.MouseButton1Click:Connect(function()

	if playing then

		if playing.Volume > 0 then

			playing.Volume -= 0.1

		end

		volumeBar.Size = UDim2.new(playing.Volume, 0, 1, 0)

		volumeBar.Text = math.floor(playing.Volume * 100 + 0.5)

	end

end)



stop.MouseButton1Click:Connect(function()

	if playing then

		playing:Stop()

		current.Text = "Currently Playing: "

	end

end)



musicButton.MouseButton1Click:Connect(function()

	frame.Visible = not frame.Visible

end)



for _, song in pairs(music:GetChildren()) do

	local track = Instance.new("TextButton")

	track.Parent = scrFrame

	track.Text = song.Name

	track.Font = Enum.Font.PatrickHand

	track.TextScaled = true



	track.MouseButton1Click:Connect(function()

		current.Text = "Currently Playing: "..track.Text

		playMusic(music[track.Text])

	end)

end

Here is the layout of the objects related to the script:
image

I’m new to scripting and I would love if you guide me to what exactly I should do or replace since I’ve had this issue for a really long time and there isn’t any video explaining it so I figured I should put it here so it’s more specific!

1 Like

Only localscripts work in a GUI. If you want to make a normal script do the functions, you’re going to need a RemoteEvent. This can be done simple, like this:
LocalScript (Sender):

--send information from localscript
workspace.RemoteEvent:FireServer(param1, param2)

Script (Receiver):

workspace.RemoteEvent.OnServerEvent:Connect(function(player, param1, param2)
   --code here manipulates the information from the event
   --player is the parameter which contains the player instance that fired it
end)
1 Like

Can you elaborate more, sorry :sweat_smile:

1 Like

You send information from a localscript to a serverscript.
Localscripts only work for that specific player, anything done with a localscript will be for only that player. You use a remote event to send a message from a localscript to a serverscript to play the music. Serverscripts work on the server and are used to communicate with everyone.

1 Like

Basically, you want to put it in a server script so that it replicates to all the clients using a RemoteEvent.

1 Like

Do you know what the Server and Client is? If not firstly look at this, Roblox Client-Server Model

Firstly local scripts work only in a few folders, and normal scripts work in other folders. You cannot just put them anywhere you like. To do something in the client and let the server know you can use a remote event, Remote Functions and Events this will tell the server that you did something client sided.

You can detect the client-side from the server-side by using remoteEvent.OnServerEvent:Connect(function)
If you want to fire the event you will use,
remoteEvent:FireServer()

Like functions you can also pass parameters, remoteEvent:FireServer(player)

1 Like

oh alr! So what do i put exactly in those scripts? and also where do I put the line in the GUI’s script that sends the information to the server script

Also is the music gui only for admins, or does everyone have their own music gui?

If everyone has their own music gui, ignore the first reply I sent as that is not what you are looking for. Neither is the other replies from @daisytheghostchild98

1 Like

I made a script so that the button that opens the gui can only be opened by people with a specific role so they can control the music

Then yes, the first response I sent is correct. You want to fire an event to the server so that all players can receive it.

Firstly create a RemoteEvent in your ReplicatedStorage and name it PlayMusic

A script in ServerScriptService

local remoteEvent = ReplicatedStorage:WaitForChild("PlayMusic")

local function playMusic(music)
    music:Play()
end

remoteEvent.OnServerEvent:Connect(playMusic)```

A local script wherever you put it in your GUI,

local function playMusic(sound)

if playing then

	playing:Stop()

end

remoteEvent:FireServer(sound)

playing = sound

playing.Volume =  tonumber(volumeBar.Text) / 100

end

Is this correct?

I put the second script after the main local script:
image

And put a script in serverscriptservices:
image

where everything is:
image

1 Like

Test it out! It should work, for the volume, you can follow the same steps.

You do need to change game.ReplicatedStorage.RemoteEvent to game.ReplicatedStorage.PlayMusic though

I tried testing with a friend and it didn’t work sadly

1 Like

Those stronger in scripting can correct me here, but I believe your sound file needs to be parented to the workspace for everyone to hear it.

I just did and it still doesn’t work for some reason

1 Like

Did you make sure to use the proper assetid prefix?
For sounds it should be "rbxassetid://1234567890"

The music is in a folder, not in the script

1 Like


it says this for some reason

Replace your playMusic function on the Server with this

local function playMusic(player, music)
    music:Play()
end

I mean if you’re trying to load different audios, then you should use that prefix. This is because it loads them properly.

1 Like