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

[MADE IT WORK!]My button to turn the music on and off is not working for some reason?

Asked by 4 years ago
Edited 4 years ago

Im trying to make the music turn on and off (currently testing). I can't see a problem. Help.

script.Parent.MouseButton1Click:Connect(function()
    if script.Parent.Value.Value == '1' then
        script.Parent.Parent.Parent.Parent.On.TextLabel.Text = 'Off'
        script.Parent.Value.Value = '0'
    end
    if script.Parent.Value.Value == '0' then
        script.Parent.Parent.Parent.Parent.On.TextLabel.Text = 'On'
        script.Parent.Value.Value = '1'
    end
end)
0
you arent modifying any sound objects in your script. theking48989987 2147 — 4y
0
I am testing to see if the button works currently, ill change the code for the script later MradmannMvip 50 — 4y
0
song* MradmannMvip 50 — 4y

2 answers

Log in to vote
0
Answered by
I_Nev 200 Moderation Voter
4 years ago

You should probably use something like this

local on = true
script.Parent.MouseButton1Click:Connect(function()
    if on == true then
        script.Parent.Parent.Parent.Parent.On.TextLabel.Text = 'Off'
        on = false
elseif on == false then
        script.Parent.Parent.Parent.Parent.On.TextLabel.Text = 'On'
        on = true
    end
end)

Sorry if this don't work, but it looks like it should for what you're trying to accomplish.

0
I forgot to say after the part where it sets the text make it set the music volume to either 1 or 0 I_Nev 200 — 4y
0
ok i will test it tomorrow MradmannMvip 50 — 4y
Ad
Log in to vote
0
Answered by 4 years ago
local ToggleValue = script.Parent:WaitForChild('Value') -- Looking for the value object

script.Parent.MouseButton1Click:Connect(function() -- Click function
    ToggleValue.Value = not ToggleValue.Value -- Alternates the value between true and false

    if ToggleValue.Value then -- If ToggleValue is true...
        script.Parent.Parent.Parent.Parent.On.TextLabel.Text = 'Off'
    else -- If ToggleValue isn't true...
        script.Parent.Parent.Parent.Parent.On.TextLabel.Text = 'On'
    end
end)

Answer this question