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

Can You Make A Sound Local Using a Global Script?

Asked by 5 years ago

Is it possible to have a sound play for only the local player through use of a global script? I tried parenting a sound to the player's PlayerGui and then playing it, but that didn't seem to work. Any suggestions? Or do I have to use a LocalScript? Thanks in advance for anyone who helps out.

0
you could change that around just throw the sound and gui into StarterGui and the event into Replicated Storage of course Donut792 216 — 5y

1 answer

Log in to vote
0
Answered by 5 years ago
Edited 5 years ago

I would probably use Remote Events. Here's what a localscript (inside of startergui) might look like:

local r = game:GetService("ReplicatedStorage")
r.playSound.OnClientEvent:connect(function(songName)
    workspace[songName]:Play()
end)

And then in a regular script inside of ServerScriptService:

local player = [insert player to hear the sound]
local soundId = [sound name inside of workspace]
local r = game:GetService("ReplicatedStorage")
r.playSound:FireClient(plr,soundId)

So yes, you do have to use localscripts, but you can integrate them with regular scripts. Hope this helps!

EDIT: As said in the comments by RSASDSA, "SoundService.RespectFilteringEnabled must be on for this to work properly."

So in the regular script, you should add:

game:GetService("SoundService").RespectFilteringEnabled = true
0
note: SoundService.RespectFilteringEnabled must be on for this to work properly RSASDSA 72 — 5y
0
@RSASDSA, I added that to the answer! Thanks for letting me know. MoonBarc 24 — 5y
Ad

Answer this question