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

How to use ClickDetectors and if statements?

Asked by 10 years ago

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
0
:D raystriker6707 30 — 10y

1 answer

Log in to vote
1
Answered by
Azarth 3141 Moderation Voter Community Moderator
10 years ago

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)
Ad

Answer this question