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

How to use ClickDetectors and if statements?

I am trying to make a mute button on my game and I am having problems. I can't insert a click detector in my textbutton in my starter gui... help? I also am trying to make it mute the music. Here is the script to mute the music,

function mute()
		if game.StarterGui.MusicMUTE.TextButton.Text = "Mute" then
		game.Workspace.Music:Stop()
	end
end

1 comment

0

:D

1 answer

✓ Accepted answer

ClickDetectors go in Parts, not GUI's. TextButton's have a few different Events for this - the ones with lightning bolts are events. Also, you don't change things in StarterGUI. The GUI in StarterGui replicates to your player when you're in the game to a folder called PlayerGui, that's where you can interact with your GUI.

-- Put a LocalScript in your ScreenGUI

local music = Workspace:WaitForChild("Music")
local gui = script.Parent:WaitForChild("MusicMUTE")
local button = gui:WaitForChild("TextButton")

button.MouseButton1Click:connect(function()
	if button.Text == "Mute" then 
		music:Stop()
		button.Text = "Play"
	else
		music:Play()
		button.Text = "Mute"
	end
end)

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