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

1local function onClick()
2 
3      if game.StarterGui.ScreenGui.Enabled then
4            game.StarterGui.ScreenGui.Enabled = false
5      elseif
6            game.StarterGui.ScreenGui.Enabled = false then
7            game.StarterGui.ScreenGui.Enabled = true
8      end
9end

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

1local function onclick()

It must be:

1[the location of the button].MouseButton1Click:Connect(function()
2 
3 
4end)

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

1game.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

1[the location of the button].MouseButton1Click:Connect(function()
2    game.Players.LocalPlayer.PlayerGui.ScreenGui.Enabled = not game.Players.LocalPlayer.PlayerGui.ScreenGui.Enabled
3end)
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:

01local Button = script.Parent
02local 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.
03 
04function OnClick()
05    if Gui.Enabled == true then
06        Gui.Enabled = false
07    elseif Gui.Enabled == false then
08        Gui.Enabled = true
09    end
10end
11 
12Button.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

1local Frame = --Object Value here
2--Script By Sabrna563
3local Function Onclick()
4    if Frame.visible  then
5    Frame.visible = false
6    else
7    Frame.visible = true
8end

Answer this question