I’m trying to make it to where when a gui is enabled a sound plays, and then when the gui is not enabled the sound stops. I have my script below placed into a ScreenGUI in which my folder of sounds is also placed however the sound is not playing when the gui is enabled.
local sound1 = soundfolder.sam
local sound2 = soundfolder["cat-laugh-meme-1"]
local sound3 = soundfolder["frog laughing meme"]
local gui = script.Parent
if gui.Enabled == true then
sound1:Play()
sound2:Play()
sound3:Play()
else
sound1:Stop()
sound2:Stop()
sound3:Stop()
end
Since this is just an if statement it only runs once when the game starts. You need to connect the property changing to a function like this,
gui:GetPropertyChangedSignal("Enabled"):Connect(function()
if gui.Enabled == true then
sound1:Play()
sound2:Play()
sound3:Play()
else
sound1:Stop()
sound2:Stop()
sound3:Stop()
end
end)