Questions about sounds

I’m putting all my sounds inside SoundService. If I play it from a LocalScript it plays to the Client. But if I play it through a server script will it play to the server? Because I’m trying to play a sound whenever a player has purchased something:

if gunsData[player].PurchaseDecision then
				purchaseSound:Play()
				purchase(player, itemType, item)
			end

It plays the sound when I buy something, but I can’t test it without having an alt or getting someone trustworthy on to test, so I’m not sure if it’s just playing for the client or the whole server.

1 Like

You can test it using a local server (go into the test tab in the toolbar in studio).

Anything on the client (LocalScripts, normal scripts, etc.) won’t replicate to the server.

I can’t really test with two players though. If I go server test on studio with two players, then local sounds will still play through my computer, because both the tabs will have sound, so irrelevant if it’s client or server

Hm, true.

Isn’t there an option to turn off sounds from the client when it isn’t in focus (Under the Settings in studio).

Have you tried using this function?:

http://wiki.roblox.com/index.php?title=API:Class/SoundService/PlayLocalSound

After all in the documentation, it does state that the sound specified “…will only be heard by the client calling this function.”

It depends on where the sound is, normally. However, you should always have RespectFilteringEnabled enabled. This makes it so that sounds, no matter where they are, that are played by a client will only be played on that client. This is to prevent exploiters from playing sounds whenever they want. Assuming you’re also using FilteringEnabled

The cost of doing so is that you have to then manage telling every other client to play sounds legitimately, though it is worth it. With this enabled, you don’t need to ask someone to help you test if others can hear the sound, as if the sound is being played from a local script you can be 100% sure it is only going to play on that client.

2 Likes

If you play a sound through a LocalScript it already only plays through the client. So I don’t know what use of that function would be if it only runs Client Side. I believe if you do sound:Play() inside a Server script then it runs to all players, but I don’t know. I need to be able to play a sound to only the client but have it run through a server script

This isn’t true in all cases. It depends on where the sound is, and whether or not the game is FilteringEnabled and RespectFilteringEnabled is enabled in SoundService.

Well I’ve turned it on. I’ve noticed that if i do sound:Play() in a server script, it plays when i got play solo, but if I actually play the game online it doesn’t make a sound