Playing a sound for 1 player on the server (serverscript)

Hello,

how can I play a sound on my serverscript but without every player on the server hearing it?
I know how to play a sound don’t worry. But there’s a thing called :PlayLocalSound or something but it never worked for me. Does that actually work how I think it works?
Whats the most effective way of playing a sound for 1 player on the server?
In the past i made it via maxdistance and stuff but is there a better way? I heard when you parent a sound to a basepart it automatically has a maxdistance?

1 Like

One way I can think of doing this is to have a Script fire a Remote Event to the Player you want to play the sound on, passing the path to the sound as well, which will then be received by a Local Script that listens to that Remote Event, then the Local Script will use the SoundService to use the :PlayLocalSound function.

Here’s an example I made real quick:

-- Server
local plrs = game:GetService('Players')
local RS = game:GetService('ReplicatedStorage')
local RE = RS.PlayLocalSoundTrigger -- The Remote Event in Replicated Storage

plrs.PlayerAdded:Connect(function(plr)
	plr.Chatted:Connect(function(msg)
		if msg == "test" then
			RE:FireClient(plr, game.Workspace.CityAmbience) -- Passing the path to the Sound
		end
	end)
end)

-- Client
local RS = game:GetService('ReplicatedStorage')
local RE = RS.PlayLocalSoundTrigger

RE.OnClientEvent:Connect(function(sound)
	game:GetService('SoundService'):PlayLocalSound(sound)
end)

Hopefully this helps.

If you want to play a sound in a 3D setting for one player call Play() through/on it via a local script.

workspace.Part.Sound:Play() --Plays a sound that attentuates from a part for a single client (local script).

NVM.

Char Limits

I found out that PlayLocalSound is only working for plugins, its not working in the actual game.

Yes but my script isn’t a localscript

This helped! Thank you :slight_smile: Modified it a bit though

In which case all you’d need to do is fire a RemoteEvent to the client as demonstrated here.