Basically, this script used to work. Basically, when you click a GUI, it enables the sound (AND OTHERS COULD HEAR IT). When you click the GUI again (turn it off), it stops.
Now, it only plays the sound for you and no one else can hear it. This is vital for the system I'm using it for. If someone could help, that'd be fantastic! (this is a local script, located inside of a GUI "text" button) If anyone has any ideas at all, please let me know?
local active = false function click() if active == false then sound = Instance.new("Sound", game.Players.LocalPlayer.Character.Torso) sound.SoundId = "http://www.roblox.com/asset/?id=147605033" sound.Volume = 1 sound.Looped = true sound:Play() script.Parent.Selected = true active = true elseif active == true then sound:Destroy() script.Parent.Selected = false active = false end end script.Parent.MouseButton1Down:connect(click)
That is because you are using LocalPlayer
to parent the sound to the character. If you want everyone in the server to hear it use a ServerScript
and also parent it to the workspace not the character. Don't use LocalScript
use ServerScript
.
I hope I helped and thank you for reading this answer.
~~ KingLoneCat
It turns out that the Play method will only play the sound on that client if used in a local script. However we can fix this by using a RemoteEvent to tell the server to play the sound for us:
Server Script
local remoteEvent = game.ReplicatedStorage.RemoteEvent remoteEvent.OnServerEvent:connect(function(player, sound) sound:Play() end
Local Script
local remoteEvent = game.ReplicatedStorage.RemoteEvent local sound local active = false function click() if active == false then sound = Instance.new("Sound", game.Players.LocalPlayer.Character.Torso) sound.SoundId = "http://www.roblox.com/asset/?id=147605033" sound.Volume = 1 sound.Looped = true remoteEvent:FireServer(sound) script.Parent.Selected = true active = true elseif active == true then sound:Destroy() script.Parent.Selected = false active = false end end script.Parent.MouseButton1Down:connect(click)