I was making a script with a SurfaceGUI button that would play/stop music if it was clicked on. It tried the below script but it didn't work.
local button = script.Parent local sound = button:WaitForChild('Sound') local function onButtonClick() if sound.IsPlaying then sound:Stop() else sound:Play() end end button.MouseButton1Click:connect(onButtonClick)
What did I do wrong?
So you were accessing the button not the sound when you did your sound variable.
--Make sure the sound is inside the frame. local button = script.Parent local sound = script.Parent.Parent.Sound --Put the name of the sound object here local function onButtonClick() if sound.IsPlaying then sound:Stop() else sound:Play() end end button.MouseButton1Click:connect(onButtonClick)