Serversided Music Player GUI

Hey, I’m trying to make a Music Player that I can use to Play music and everyone can hear it. I want to input the ID in a textbox and play it. I’ve tried some stuff with remotes and it hasn’t worked. If anyone can help id appreciate it

Hi there! Do you mind sending what you have tried so people can tell you how to improve, and so you can further understand where you messed up? Also, you will need a local script, remote event, and regular script to my knowledge in order to make this work.

Sure thing.

Server Script:

script.Parent.Song_Event.OnServerEvent:Connect(function()
	local idBox = script.Parent.Parent:WaitForChild("ID")
	local playButton = script.Parent.Parent:WaitForChild("Play")
	local stopButton = script.Parent.Parent:WaitForChild("Stop")
	local sound = Instance.new("Sound",game.SoundService)

	playButton.MouseButton1Click:Connect(function()
		sound.SoundId = "rbxassetid://".. idBox.Text
		wait(0.1)
		sound:Play()
		sound.Volume = 1.5
		sound.Looped = true
	end)

	stopButton.MouseButton1Click:Connect(function()
		sound:Stop()
	end)
end)

Local Script

local click = script.Parent

click.MouseButton1Click:Connect(function()
	click.Song_Event:FireServer()
end)

The problem is that the server can’t see what is written inside of the textbox. pass it along from the client.

local click = script.Parent

click.MouseButton1Click:Connect(function()
	click.Song_Event:FireServer(script.parent.Parent.ID.Text)
end)
script.Parent.Song_Event.OnServerEvent:Connect(function(ID)
	local playButton = script.Parent.Parent:WaitForChild("Play")
	local stopButton = script.Parent.Parent:WaitForChild("Stop")
	local sound = Instance.new("Sound",game.SoundService)

	playButton.MouseButton1Click:Connect(function()
		sound.SoundId = "rbxassetid://".. ID
		wait(0.1)
		sound:Play()
		sound.Volume = 1.5
		sound.Looped = true
	end)

	stopButton.MouseButton1Click:Connect(function()
		sound:Stop()
	end)
end)
1 Like

I just tested that didn’t seem to work?

Feel free to let me know if you have any issues or any questions.
I have no idea what he was trying to do (no offense to him), but this is what I would do:

Local Script:

local click = script.Parent --Assuming this is a button, if not change it to the button
local TextBox = script.Parent.Parent.TextBox --Change this to the textbox that the sound ID is being typed into
local Song_Event = script.Parent.RemoteEvent --Change this to the location of you event
click.MouseButton1Click:Connect(function() --When the button is clicked
   Song_Event:FireServer(TextBox.Text) --When we fire the server we want to send the ID to the Script
end) --End the function

Script:

local Song_Event = script.Parent.RemoteEvent --Change this to the location of your event
Song_Event.OnServerEvent:Connect(function(ID) --When the event is fired
	local song = Instance.new("Sound") --Create a new sound
	song.Parent = workspace --Change its parent to workspace so the whole server can hear it
	song.SoundId = "rbxassetid://"..ID --format the ID and connect it
	repeat wait() until song.Loaded() -- Wait until the soung is loaded
	song:Play()	--Play the sound
end) --End the function

Whenever I click play it just inserts a sound into workspace and that is it

Where is the variable PlayButton located, Also is this in gui?

Is there an error that displays in the output?

Nope. I checked explorer and all it shows is a blank sound in workspace

Mind sending an explorer view of what you are doing? Just so it’s a bit easier to assist you.

Oh wait sorry I just found and error. It wasn’t showing up for the first but ill send the error text.

Players.Scripticz_X.PlayerGui.MusicPlayer.MusicArea.Music.Play.Script:5: attempt to concatenate string with instance

Ah, there was an error in both of our scripts. Add a “plr” parameter before “ID” in the OnServerEvent. The first parameter of a remote event is always the player who fired it.

This should fix the error and work. I have also made it so it only creates one sound and uses the same one every time, to avoid lag and unused sounds.
Assuming you are still using my script, change the regular server script to this:

local Song_Event = script.Parent.RemoteEvent --Change this to the location of your event
local song = Instance.new("Sound") --Create a new sound
song.Parent = workspace --Change its parent to workspace so the whole server can hear it
Song_Event.OnServerEvent:Connect(function(plr, ID) --When the event is fired
	song.SoundId = "rbxassetid://"..tonumber(ID) --format the ID and connect it
	wait(.1) --give it a milisecond to load
	song:Play() --play the song
end) --End the function
1 Like

Theres a new error now. Players.Scripticz_X.PlayerGui.MusicPlayer.MusicArea.Music.Play.Script:6: attempt to call a RBXScriptSignal value

Oh nevermind I fixed it myself. Thank you for the help!