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 5 years ago
Edited 5 years ago

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

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

2 answers

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

You should probably use something like this

01local on = true
02script.Parent.MouseButton1Click:Connect(function()
03    if on == true then
04        script.Parent.Parent.Parent.Parent.On.TextLabel.Text = 'Off'
05        on = false
06elseif on == false then
07        script.Parent.Parent.Parent.Parent.On.TextLabel.Text = 'On'
08        on = true
09    end
10end)

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 — 5y
0
ok i will test it tomorrow MradmannMvip 50 — 5y
Ad
Log in to vote
0
Answered by 5 years ago
01local ToggleValue = script.Parent:WaitForChild('Value') -- Looking for the value object
02 
03script.Parent.MouseButton1Click:Connect(function() -- Click function
04    ToggleValue.Value = not ToggleValue.Value -- Alternates the value between true and false
05 
06    if ToggleValue.Value then -- If ToggleValue is true...
07        script.Parent.Parent.Parent.Parent.On.TextLabel.Text = 'Off'
08    else -- If ToggleValue isn't true...
09        script.Parent.Parent.Parent.Parent.On.TextLabel.Text = 'On'
10    end
11end)

Answer this question