Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
COMMUNITY QUESTION

Can You Make A Sound Local Using a Global Script?

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.

2 comments

0

you could change that around just throw the sound and gui into StarterGui and the event into Replicated Storage of course

1 answer

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

2 comments

0

note: SoundService.RespectFilteringEnabled must be on for this to work properly

0

@RSASDSA, I added that to the answer! Thanks for letting me know.

This discussion is preserved as it was. New answers, comments, and votes are closed.