Hello, I made a game so when you open the shop, Music plays for the person who opened the shop, But it plays to everyone on the server. plz help, I had this issue for 8 days
It is not a remote event issue, it is a replication issue. Roblox sounds are not filtered, meaning no matter where you play it (on client or on server), it will be replicated to everybody. To avoid this you can use SoundService:PlayLocalSound.
musicTable = {
{"rbxassetid://9122235754", "Rude Buster"},
{"rbxassetid://9122197945", "Bee."},
{"rbxassetid://9064962379", "Sunday"},
{"rbxassetid://9365289409", "Black Snow"}
}
local SoundService = Game:GetService("SoundService")
local StarterGui = game.Players.LocalPlayer.PlayerGui
local shop = StarterGui.Shop
local shopMusic = script.Parent.ShopMusic
local PlayingMusic = StarterGui.Shop.PlayingMusic.Text
local random1 = musicTable[math.random(1, #musicTable[1])]
local function ChangeText()
shopMusic.SoundId = random1[1]
PlayingMusic = random1[2]
end
local function PlayMusic()
SoundService:PlayLocalSound(shopMusic)
end
local function RandomizeMusic()
random1 = musicTable[math.random(1, #musicTable[1])]
end
local function PauseMusic()
shopMusic:Pause()
end
if SoundService.RespectFilteringEnabled == false then
SoundService.RespectFilteringEnabled = true
end
EventsFolder.ChangeMusic.OnClientEvent:Connect(ChangeMusic)
EventsFolder.PlayMusic.OnClientEvent:Connect(PlayMusic)
EventsFolder.PauseMusic.OnClientEvent:Connect(PauseMusic)
EventsFolder.RandomizeMusic.OnClientEvent:Connect(RandomizeMusic)
When you randomize the SoundId you index #musicTable with [1]. #musicTable returns the number of elements in the table, so you are indexing a number with a number, try replacing the above code with this:
random1 = musicTable[math.random(1, #musicTable)]
If this doesn’t work you could try debugging the code with print statements to see if the functions are being called correctly.
I don’t know how a sound would be playing for every user since he’s triggering it with a RemoteEvent? Unless he was using :FireAllClients()?
It might be helpful to rewrite the code handling the shop music. Other than that I don’t think I have encountered a bug like that before, so I don’t know what you could do.
In the local script you fire EventsFolder.TestRemoteEvent, but on the server script you only listen for EventsFolder.PlayMusic to be fired before printing.