Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
✓ ANSWER ACCEPTED

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

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)

3 comments

0

you arent modifying any sound objects in your script.

0

I am testing to see if the button works currently, ill change the code for the script later

0

song*

2 answers

✓ Accepted answer

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.

2 comments

0

I forgot to say after the part where it sets the text make it set the music volume to either 1 or 0

0

ok i will test it tomorrow

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)

This discussion is preserved as it was. New answers, comments, and votes are closed.