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

im trying to make a gui button to stop the music ?

Asked by 3 years ago
Edited by Ziffixture 3 years ago

Please encode Lua code in the Lua block code tag (look for the Lua icon in the editor).

I'm trying to make a GUI button that stops music, but when I press it nothing happens. This is my code:

local music = ('musicplay1')
db = true
script Parent.MouseButton1ClickConnect(function()
    if db == true and music then
        db = false
        script.Parent.Text = ("Music Off")
        game.Workspace.Audio.musicplay1:Pause()
    else
        db = true
        script.Parent.Text = ("Music On")
        game.Workspace.Audio.musicplay1:Resume()
    end
end)

Can someone help me?

0
Open your output. The window is a vital component to programming; your code has a syntax error on line 3, you would've been informed—the Linter would've caught it too, you should see an underline in your editor. Ziffixture 6913 — 3y
0
You have zero* need to wrap your Strings in parenthesis, unless you wish to call methods on them directly. Ziffixture 6913 — 3y
0
Your 'music' variable on line 1 is redundant and has no significance to the program whatsoever, I assume you meant to check whether 'musicplay1' was a member of workspace. To do so, allocate through :FindFirstChild() and continue to affirm the Instance with your conditional statement. Ziffixture 6913 — 3y
0
You're referencing the Script's Parent and 'musicplay1' frequently, use a variable—for 'musicplay1' as mentioned above, you can use the variable allocating the Instance, after confirming its existence of course. Also ensure you're using meaningful identifiers, for example, 'db' is a poor naming choice (consider "Debounce" or better yet, "Toggle") Ziffixture 6913 — 3y
0
There is a global titled 'workspace' that more efficiently points to 'game.Workspace'. Ziffixture 6913 — 3y

Answer this question