Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
0

How to play a Server-side sound just for the client without local scripts? [SOLVED]

Asked by 4 years ago
Edited by DeceptiveCaster 4 years ago

Hi!

I have a Remote Event that's sent to a script under ServerScriptStorage, in the course of that Remote Event, I need to play a Sound, with info for that Sound sent from the RemoteEvent. The audio does play, but it plays for everyone in the server, and I need just the player who triggered the even to hear it.

Script in ServerScriptStorage

TheRemoteEvent.OnServerEvent:Connect(function(Player,SoundSent) 

local NewSound = SoundSent.SoundId
local SoundForPlayerToHear = Instance.new("Sound")
SoundForPlayerToHear.SoundId = NewSound 


-- Other Stuff Happens First

SoundForPlayerToHear:Play() 

end)

Here's where it gets fun, the "SoundSent" Sound file is from a folder stored inside the Player, which can change every time the player loads the game and chooses a different set of sound files to have. So there's never a specific SoundId to point to as it changes, but the Local Script that fires the Remote Event to the Server includes the necessary Sound file, "SoundSent".

But as stated before, when I do this, everyone hears the audio being played, and I only want the player to hear it.

How should this be tweaked to where it only plays for the player who triggered the event, while still keeping it inside this Server Script?

Thanks!

0
You don't. You play it locally. Why do you want to play it server side but only one player should hear it. Any changes made on the server are replicated to the clients. User#24403 69 — 4y
0
I know, but the way my script is set up requires the server script to be the one that plays the sound. Any thoughts on how to make it to where only the player hears it and not the entire server? Never2Humble 90 — 4y
1
Play it locally. Period. If you wish, you can listen for RemoteEvent.OnClientEvent, and the listener plays the sound. Then, from the server, call RemoteEvent:FireClient. In some way the server is playing it by firing OnClientEvent. User#24403 69 — 4y
0
Thank you. :) My game is menu-based, so if a player presses the "sword" button, I don't want the sound effect to happen until the system is ready to show the sword swinging animation, which could be X amount of time later, depending on other events that happen first. Never2Humble 90 — 4y

Answer this question