How to locally play a sound when the player presses the gui button?
I thought about placing already pre-adjusted sound in player gui and just play it, but is it safe? How do I make it play locally?
How to locally play a sound when the player presses the gui button?
I thought about placing already pre-adjusted sound in player gui and just play it, but is it safe? How do I make it play locally?
Just reference the sound inside SoundService
if you want to locally play it, or you can use SoundService’s PlayLocalSound()
function
--This should be a LocalScript
local Button = script.Parent
local Sound = game.SoundService:WaitForChild("SoundToPlay")
Button.MouseButton1Down:Connect(function()
Sound:Play()
end)
Thank you also I wanted to ask you, where should I place the sound or I have to create it through a script?
Sounds always play locally if you play them from a LocalScript. There’s only one exception where a LocalScript-played sound will not be strictly local in which all of the following must be true:
In this case, sound playback will replicate. Otherwise just use a LocalScript and you’re good.
So if I make a local script and enable IsPlaying property of a sound which is already located in starter gui it will play locally?
IsPlaying is a read only property describing the playback state of the sound. Just call Play explicitly.
You can use this method, but it does not work if you are trying to use SoundEffects with it
game:GetService("SoundService"):PlayLocalSound(sound)
I personally have found it to be a lot more reliable than :Play(), but that is from personal experience
RespectFilteringEnabled was the issue for me!!! thanks!!