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?
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)