BoomBox not playing music

Hello!
My boombox script won’t work help!

Problem

  19:32:28.931 - ServerScriptService.Events:23: attempt to concatenate string with Instance

Event

PlaySound.OnServerEvent:Connect(function(id, Player)
	Player.Character.BoomBox.Handle.Sound.SoundId = "rbxassetid://"..id
	Player.Character.BoomBox.Handle.Sound:Play()
end)

local script

local Player = game.Players.LocalPlayer
local rep = game.ReplicatedStorage
local PlayerGui = Player.PlayerGui
script.Parent.Equipped:Connect(function()
	PlayerGui.BoomBoxGui.Enabled = true
end)

script.Parent.Unequipped:Connect(function()
	PlayerGui.BoomBoxGui.Enabled = false
	PlayerGui.BoomBoxGui.Frame.Visible = false
	PlayerGui.BoomBoxGui.OpenFrame.TextButton.Text = "Open BoomBox"
	PlayerGui.BoomBoxGui.Frame.Playing.SongName.Text = "None"
	PlayerGui.BoomBoxGui.Frame.SearchBar.Text = ""
	
	local Sound = script.Parent.Handle.Sound
	rep.StopSound:FireServer(Sound,Player)
end)
	
local SongList = Player.PlayerGui:WaitForChild("BoomBoxGui").Frame
for i, v in pairs(SongList.Songs:GetChildren()) do
	if v:isA("GuiButton") then
		v.MouseButton1Click:Connect(function()
			local id = v.SongId.Text
			local Sound = script.Parent.Handle.Sound
			SongList.Playing.SongName.Text = v.Name
			rep.PlaySound:FireServer(Player,id,Sound)
		end)
	end
end

SongList.MusicStop.MouseButton1Click:Connect(function()
	local Sound = script.Parent.Handle.Sound
	SongList.Playing.SongName.Text = "None"
	rep.StopSoundButton:FireServer(Sound,Player)
end)

The OnServerEvent, automatically passes player as the first arguement, so it should be like the below instead. Also you don’t need to pass Player arguement in the client side, as it can result in exploiters abusing it later.

PlaySound.OnServerEvent:Connect(function(Player, id)
...
end)

References To Documentations:

1 Like

I already tried both ways but it won’t play the music. ik that btw I was just testing if it would work

1 Like

Oh, alright. Be sure to fix that and after that, instead of passing the Sound instance directly pass the Sound.SoundId to the RemoteEvent, as thats what you need to use in the server side.

1 Like

So u want me to change the sound in the local script then fire it in a global handler?

1 Like

Actually could you give me your fixed script first, I am having confusion on understanding it now, as the first problem my eyes always see is the Arguements being called wrongly.

1 Like
PlaySound.OnServerEvent:Connect(function(Player, id)
	Player.Character.BoomBox.Handle.Sound.SoundId = Player.Character.BoomBox.Handle.Sound.SoundId
	Player.Character.BoomBox.Handle.Sound:Play()
end)
``

local Player = game.Players.LocalPlayer
local rep = game.ReplicatedStorage
local PlayerGui = Player.PlayerGui
script.Parent.Equipped:Connect(function()
PlayerGui.BoomBoxGui.Enabled = true
end)

script.Parent.Unequipped:Connect(function()
PlayerGui.BoomBoxGui.Enabled = false
PlayerGui.BoomBoxGui.Frame.Visible = false
PlayerGui.BoomBoxGui.OpenFrame.TextButton.Text = “Open BoomBox”
PlayerGui.BoomBoxGui.Frame.Playing.SongName.Text = “None”
PlayerGui.BoomBoxGui.Frame.SearchBar.Text = “”

local Sound = script.Parent.Handle.Sound
rep.StopSound:FireServer(Sound,Player)

end)

local SongList = Player.PlayerGui:WaitForChild(“BoomBoxGui”).Frame
for i, v in pairs(SongList.Songs:GetChildren()) do
if v:isA(“GuiButton”) then
v.MouseButton1Click:Connect(function()
local id = v.SongId.Text
local Sound = script.Parent.Handle.Sound
SongList.Playing.SongName.Text = v.Name
Sound.SoundId = “rbxassetid://”…id
rep.PlaySound:FireServer(Player,id,Sound)
end)
end
end

SongList.MusicStop.MouseButton1Click:Connect(function()
local Sound = script.Parent.Handle.Sound
SongList.Playing.SongName.Text = “None”
rep.StopSoundButton:FireServer(Sound,Player)
end)


oh wow I'm dumb lol it works

What I did was start playing the song from the local script, then I I played the same sound in a global handler by getting the sound id and replaying it.

Oh, Cool if it works, I still see an error point at this line though:

rep.PlaySound:FireServer(Player,id,Sound)

You don’t need to pass the Player variable in there, the Server will handle that, you just pass whats needed except the Player Instance in the server side.

1 Like