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

How to make a toggle to make a frame appear/disappear?

Asked by 4 years ago

I want to do a Button or Toggle so when you press it some frame disappear/appear i dont have a script, ia actually dont know much about scripting but my try would be something like

local function onClick()

      if game.StarterGui.ScreenGui.Enabled then
            game.StarterGui.ScreenGui.Enabled = false
      elseif
            game.StarterGui.ScreenGui.Enabled = false then
            game.StarterGui.ScreenGui.Enabled = true
      end
end

Yeah, i know i can make a variable so i dont write game.StarterGui.ScreenGui but welp, i also know that the script its wrong but i dont know what to do to make it right

3 answers

Log in to vote
0
Answered by 4 years ago

First of all i recommend making the frame invisible instead of disabling the GUI, unless there are different frames and you want to make all of them go invisible. (everything must go in a local script) instead of

local function onclick()

It must be:

[the location of the button].MouseButton1Click:Connect(function()


end)

in between the sentence, put this: (also dont use starter GUI as the location)

game.Players.LocalPlayer.PlayerGui.ScreenGUI.Enabled = not game.Players.LocalPlayer.PlayerGui.ScreenGUI.Enabled

this will make everytime someone presses the button it will become the contrary of what it is [if it is enabled and u press the button it will become disabled and viceverse] here a resume

[the location of the button].MouseButton1Click:Connect(function()
    game.Players.LocalPlayer.PlayerGui.ScreenGui.Enabled = not game.Players.LocalPlayer.PlayerGui.ScreenGui.Enabled
end)
0
everythin in a local script edusan3005 10 — 4y
0
Thanks, it worked! El_Tycoonero0Delgado 18 — 4y
Ad
Log in to vote
0
Answered by 4 years ago
Edited 4 years ago

One issue I see right off the bat, is that you are calling your ScreenGui from the StarterGui. I don't think this would work as the gui is cloned to the PlayerGui once the game starts, so your fixed script should look more like this:

local Button = script.Parent
local Gui = game.Players.LocalPlayer.PlayerGui:WaitForChild("Test") --- Test is just a placeholder name for a another gui that isn't the gui this script goes into.

function OnClick()
    if Gui.Enabled == true then
        Gui.Enabled = false
    elseif Gui.Enabled == false then
        Gui.Enabled = true
    end
end

Button.Activated:Connect(OnClick) -- this uses your function when a player clicks the GuiButton

I'm sorry if I provide any misinformation.

Edit: I forgot to mention that this localscript was put inside of a textbutton.

Log in to vote
0
Answered by 4 years ago

Use this instead

local Frame = --Object Value here
--Script By Sabrna563
local Function Onclick()
    if Frame.visible  then
    Frame.visible = false
    else
    Frame.visible = true
end

Answer this question