Clients can play and replicate audio?

I am currently working on a game which requires a sound to replicate to all clients. I did so inside of a local script (from StarterPlayerScripts) with some simple code. It somehow ended up replicated to all other clients aside from itself.
This also applies to module scripts being required by the client.

-- In a local Script --
local sound = workspace.Sound
task.wait(4)
if game.Players.LocaPlayer.Name == 'Player1' then -- To make sure audio plays in only one client
   sound:Play() -- Replicates to all other clients
end

The script is being ran inside of a 2-player local server, via the ‘Test’ tab inside of studio.
I’m confused as to why this is happening. Is this an intentional feature? If so, where or how can I create audios where a client won’t be able to play an audio?

You can try this – In a LocalScript
local ReplicatedStorage = game:GetService(“ReplicatedStorage”)
local PlaySoundEvent = ReplicatedStorage:WaitForChild(“PlaySound”)

PlaySoundEvent:FireServer() – Trigger the event to play the sound on the server

– In a Script (on the server)
local ReplicatedStorage = game:GetService(“ReplicatedStorage”)
local Sound = workspace.Sound
local PlaySoundEvent = Instance.new(“RemoteEvent”)
PlaySoundEvent.Name = “PlaySound”
PlaySoundEvent.Parent = ReplicatedStorage

PlaySoundEvent.OnServerEvent:Connect(function(player)
if player.Name == “Player1” then
Sound:Play()
PlaySoundEvent:FireClient(player) – Send a confirmation message back to the client
end
end)

I believe there is a miscommunication. The script I provided does play the sound. The problem that I’m having is that the sound is playing on all clients, instead of the one which played it.

i made a mistake sorry how about this

– Server-side code
addEvent(“playSoundOnClient”, true)
addEventHandler(“playSoundOnClient”, root, function(client)
triggerClientEvent(client, “onClientPlaySound”, client)
end)

– Client-side code
addEvent(“onClientPlaySound”, true)
addEventHandler(“onClientPlaySound”, root, function()
– Play your sound here
end)

Do you have SoundService.RespectFilteringEnabled turned off?

2 Likes

Wow, I did not know that was a thing. I appreciate the help!

2 Likes

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