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.