Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
0

Sound doesn't stop when pressing a GUI button?

Asked by 3 years ago
Edited 3 years ago

I know this might sound silly, since it's such a simple script. But I was trying to create "Toggle Radio" like After the Flash, and I thought this code would work, but it doesn't stop the sound or show any errors in the Developer Console. Here's my code:

local Sound1 = script.Parent.TimeAndTimeAgain -- References the sound

script.Parent.MouseButton1Down:Connect(function() -- Detects when clicked, if so commences these events
    if Sound1.Playing == false then -- If the sound isn't playing, it plays the sound
        Sound1:Play()
    else
        Sound1:Stop() -- If the sound is playing, it stops the sound
    end
end)

Thanks!

0
Try if Sound1.IsPlaying == false then WizyTheNinja 834 — 3y
0
Doesn't work CoolBlueJay000 48 — 3y
0
either your asset ID is invalid or your sound isn't called 'TimeAndTimeAgain' because there's no problems with the code, an invalid AssetID is most likely the problem. Metacalled2 142 — 3y
0
Nope, the asset ID isn't invalid and it isn't showing errors. The sound is named TimeAndTimeAgain. It's in the script CoolBlueJay000 48 — 3y
0
script's parent. CoolBlueJay000 48 — 3y

2 answers

Log in to vote
0
Answered by 3 years ago
Edited 3 years ago

Try this

local Sound1 = Instance.new("Sound")
Sound1.SoundId = "rbxassetid://1837324424" 
Sound1.Parent = script.Parent

script.Parent.MouseButton1Down:Connect(function() -- Detects when clicked, if so commences these events
    if Sound1.IsPlaying == false then -- If the sound isn't playing, it plays the sound
        Sound1:Play()
    else
        Sound1:Stop() -- If the sound is playing, it stops the sound
    end
end)
0
I don't know why it doesn't work on mine, it might be playing multiple times. But I don't get how that's possible because I'm only clicking it once. CoolBlueJay000 48 — 3y
0
Is it supposed to be a local script? Because on mine it is. CoolBlueJay000 48 — 3y
0
Yeah its supposed to be in a local script. Is this 100% the code or is this a snippit of one? This code isn't set in a loop? WizyTheNinja 834 — 3y
0
Nope. CoolBlueJay000 48 — 3y
0
This is all of the code. CoolBlueJay000 48 — 3y
Ad
Log in to vote
0
Answered by 3 years ago

Apparently, the Play and Stop() function just looped??? I'm so confused about how it was looping. But anyway, I got it fixed. Thanks for your help!

Answer this question