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

I tried to make a script to turn on and off my music. Why won't it work? (I am a beginner)

Asked by 6 years ago
Edited 6 years ago
script.Parent.MouseButton1Click:connect(function()
    game.Workspace.Music.IntoTheForest.Volume = 0
    if game.Workspace.Music.IntoTheForest.Volume>.1 then 
        game.Workspace.Music.IntoTheForest.Volume = 1
    end
end)

So this is my script. I'm trying to make a button that will turn my song (IntoTheForest) on and off. I probably did something very wrong because I am a beginner and was experimenting with the use of if and then. It didn't work, and no errors appeared in the Output. What did I do wrong? Also, turning it off works, but it can't be turned back on. I need assistance with that part of the script.

0
Hello. You do not have any syntax errors which is why you do not see any errors in the output, however you did not use audio correctly. Please refer to this wiki article on how to add audio into your game: http://wiki.roblox.com/index.php?title=Sounds#Add_with_Script . P.S.: Are you excited about school letting out? GiveMeYourPudding 64 — 6y
0
thank you! & yes, I am excited happygirl29922 -3 — 6y

1 answer

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

This script is just going to set the volume to 0 and then run the if staement which will never trigger because the volume will always be 0

Try:

script.Parent.MouseButton1Click:Connect(function()
    if workspace.Music.IntoTheForest.Volume >.1 then
        workspace.Music.IntoTheForest.Volume = 0
    else
        workspace.Music.IntoTheForest.Volume = 1
    end
end)

Hope I didn't spell anything wrong I'm on my phone rn

Basically what this does, when the button is clicked it will check to see if the volume is greater than .1 (if it is playing) then it will set it to 0. And if it is less than .1 (if it isn't playing) then it will set it to 1

Ad

Answer this question