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
1 | local 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 |
9 | 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
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
1 | local function onclick() |
It must be:
1 | [ the location of the button ] .MouseButton 1 Click:Connect( function () |
2 |
3 |
4 | end ) |
in between the sentence, put this: (also dont use starter GUI as the location)
1 | 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
1 | [ the location of the button ] .MouseButton 1 Click:Connect( function () |
2 | game.Players.LocalPlayer.PlayerGui.ScreenGui.Enabled = not game.Players.LocalPlayer.PlayerGui.ScreenGui.Enabled |
3 | end ) |
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:
01 | local Button = script.Parent |
02 | 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. |
03 |
04 | function OnClick() |
05 | if Gui.Enabled = = true then |
06 | Gui.Enabled = false |
07 | elseif Gui.Enabled = = false then |
08 | Gui.Enabled = true |
09 | end |
10 | end |
11 |
12 | 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.
Use this instead
1 | local Frame = --Object Value here |
2 | --Script By Sabrna563 |
3 | local Function Onclick() |
4 | if Frame.visible then |
5 | Frame.visible = false |
6 | else |
7 | Frame.visible = true |
8 | end |