I added a feature to mute soundfx in my game. To do this I set the volume of the sound group to 0. This works most the time, however when I start up studio and switch it immediately I get and error. The soundgroup is not nil, yet I cant access the volume. The commented out line is my code that errored initially. The code below it always warns when I attempt to access the soundgroups volume.
--game.SoundService.SoundFx.Volume = slider:GetAttribute("IsEnabled") and 1 or 0
local soundFx = game.SoundService:WaitForChild("SoundFx")
if soundFx.Volume then
soundFx.Volume = slider:GetAttribute("IsEnabled") and 1 or 0
else
warn("Volume property is missing from SoundFx") -- Always when I access volume fast
end
Its very frustrating because it only errors occasionally I have determined 100% that the code above the problem. Any ideas on how I could fix this?