Functions Question. (Basic)

Im really stupid… but I can’t find answers to this anywhere. I even asked ChatGPT.
Also warning you that im a super new Scripter.
Heres my Script =

local button = script.Parent
local button2 = script.Parent.Parent.Parent
local visible = true
local invisible = false
-- variables -------------------------------------------------------------------------------
function newgui()
	wait(0.000001) -- tester
	button.Visible = invisible -- refrences the Textbutton (Script.Parent) and sets it to invisible
	button2.Visible = visible -- refrences the Frame (Script.Parent.Parent) and sets it to visible

end

Its a basic script but my main question is how to run it by clicking the Gui Textbutton.
Thanks for helping me out Pros :sunglasses::call_me_hand:

2 Likes

First, the wait has a minimum wait time of 0.03 seconds, so your 0.000001 wont make it wait that long, it will be at least 0.03 seconds. If you want a function to run when a button is pressed do something like this:

local button = path.to.button
local function onButtonPressed()
   print("I was pressed")
end

button.Activated:Connect(onButtonPressed)
1 Like

thanks bro ur cool.
Im tryin to learn ig
:wink:

new script

local button = script.Parent
local button2 = script.Parent.Parent.Parent
local visible = true
local invisible = false
-- variables -------------------------------------------------------------------------------
function newgui()
	wait(0.03) -- tester
	button.Visible = invisible -- refrences the Textbutton (Script.Parent) and sets it to invisible
	button2.Visible = visible -- refrences the Frame (Script.Parent.Parent) and sets it to visible

end

button.Activated:Connect(newgui)
1 Like

Sorry to reply in a solved post, but I just wanted to give you a tip. Making variables for true and false isn’t necessary. Variables are only made to make scripts more simple and compact, however true and false are both just one word each, and “invisible” and “visible” are actually longer to type.

yeah I know… sometimes I just like to make longer code for my friend so its easier to understand for him.
In this case its pretty easy to understand button.visibilty = invisible\

im bad but he’s even worse

I wouldnt suggest learning it like that, similarly to what @sir_gagigo said, however if you learn it having true and false as variables you may not be able to come out of your ways, and its not very well optimized,

So i’d suggest it just be something like this,

function newgui()
	wait(0.03) -- tester
	button.Visible = false -- refrences the Textbutton (Script.Parent) and sets it to invisible
	button2.Visible = true -- refrences the Frame (Script.Parent.Parent) and sets it to visible, When visibility is true the frame can be seen.

end

even thought you said that its easier to understand if you or him want to become sucessfull scripters you need to be able to interpret the basic scripts to begin with.

My bad… this wasn’t what I hoped for. But I found a solution

button.MouseButton1Click:Connect(newgui) -- when the button is clicked, run the function newgui

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.