Issue where boombox would play audios from one player at a time

Hello, I have this issue with a boombox system I’ve made where I can only play one boombox at a time, Instead of each player being able to play their own song individually.


Here’s the hierarchy.
Server script inside the boombox.

local Boombox = script.Parent
local rep = game:GetService("ReplicatedStorage")
local sound = Boombox.Handle.Sound
local event = rep.Events.PlaySong
local Players = game:GetService("Players")

event.OnServerInvoke = function(Player, Status, Id)
	if Player == Players:GetPlayerFromCharacter(Boombox.Parent) then
		if (Status == "_Play") then
			sound.SoundId = `rbxassetid://{Id}`
			sound:Stop()
			sound:Play()
		elseif (Status == "_Stop") then
			sound:Stop()
		end
	end
end

The local script Inside the UI.

local function PlaySong()
	PlaySound(Sounds.Click)

	local Id = tonumber(RadioUI.Input.Text)

	local Play = Events.PlaySong:InvokeServer("_Play", Id)
	
	local success, Info = pcall(function()
		return Services.MarketplaceService:GetProductInfo(Id, Enum.InfoType.Asset)
	end)
	
	if success then
		print(`\n Id: {Info.AssetId} \n Name: {Info.Name} \n Creator: {Info.Creator.Name} \n Creation date: {Info.Created}`)
	end
end

RadioUI.Play.MouseButton1Click:Connect(PlaySong)

You’re handling the same function for each player’s boombox, this line will always return true no matter what because Player is defined by the player that requested the event on the server it will always return true which is why all of your sounds are being overwritten.

if Player == Players:GetPlayerFromCharacter(Boombox.Parent) then
1 Like

I’m a bit slow, can you give me the solution to this code my apologies for the request :sweat_smile:
(Edit): I fixed it thank you!

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.