RemoteEvents "Server to Client" not working

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

Script:

this.ProximityPrompt.Triggered:Connect(function(player)
	Shop.Activated = true
	
	EventsFolder.PlayMusic.FireClient(player,  Player)
end)

Local script:

local function PlayMusic(player)
	shopMusic:Play()
end

EventsFolder.PlayMusic.OnClientEvent:Connect(PlayMusic)

1 Like

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.

Check if SoundService.RespectFilteringEnabled is true.

1 Like

It’s still not working :sad:

LocalScript:

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)
1 Like

What exactly is not working? Can you hear the sound on the server side and other clients too?

I don’t hear any sounds, Nothing plays

On line 4 in your server script when you fire the event you have it written as:

EventsFolder.PlayMusic.FireClient(player, Player)

When it should be written as:

EventsFolder.PlayMusic:FireClient(player, Player)

Functions are usually called with a “:” rather than a “.”, and it appears that you sent the Player twice, I don’t know if this is intended or not.

I fixed it, But nothing still plays

That’s strange, it might’ve been removed by the recent audio update. Do you own the audio?

I think I might’ve figured it out.

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.

Roblox launched an update — If you don’t own this sounds it won’t play.

He’s not saying sounds will not play, he’s saying sounds will play but for everybody.

Oh, I misread the question.

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.

Nothing prints in the output :neutral_face:

script:

this.ProximityPrompt.Triggered:Connect(function(player)
	Shop.Activated = true
	
	EventsFolder.PlayMusic:FireClient(player,  Player)
end)

EventsFolder.PlayMusic.OnServerEvent:Connect(function()
	print("aaaaaaaaaaaaaaaaaaa")
end)

local script:

EventsFolder.PlayMusic.OnClientEvent:Connect(function()
	SoundService:PlayLocalSound(shopMusic)

	EventsFolder.TestRemoteEvent:FireServer()
end
1 Like

In the local script you fire EventsFolder.TestRemoteEvent, but on the server script you only listen for EventsFolder.PlayMusic to be fired before printing.

I fixed it

local scripts doesn’t work on workspace

sadwaltuh

bro why did it bump

2 Likes