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

Items not turning invisible?

Asked by
Ap_inity 112
7 years ago
Edited 7 years ago

I have a script, that when you press a button, it would do as the following:

script.Parent.MouseButton1Click:connect(function()
    script.Parent.Parent.Frame1.Visible = true
    script.Parent.Parent.Main.Visible = false
end)

It doesn't make the frame invisible..? But i am pretty sure i did everything right.

0
Could you show a screenshot of your hierarchy? Goulstem 8144 — 7y

2 answers

Log in to vote
2
Answered by 7 years ago
Edited 7 years ago

From what I've looked over, your code have two potential problems that can be fixed, but I'm only assuming what I'm thinking is correct.

The problems from my perspective are:

  1. The objects may not have loaded at the item of execution,

  2. Or you're not using a TextButton or ImageButton for the GUIs click functions. (For this, because it seems you understand how to do this, I wont explain.)

I'm guessing it's option 1, because of how your code is set to directly get to the objects and set a property (of it/ theirs) immediately; there's a way to prevent this, and that way is using the WaitForChild function!

What the WaitForChild function does is it yields the code until an object that has the same name as the argument you gave the function spawns/ exists inside the selected/ specific parent.

But before we apply the WaitForChild function, it'd be best if we add Variables first, so that we don't have to keep rewrite the same thing over-and-over again. c;

Now, to get this outta the way, lets add the variables first:

local zeScriptsParent
local zeScriptsParentParent
local zeFrame
local zeMain

script.Parent.MouseButton1Click:Connect(function()
       script.Parent.Parent.Frame1.Visible = true
       script.Parent.Parent.Main.Visible = false
end)
-- I fixed the tabbing c;

...Don't ask why I set them up like that.

Lookin' much better than before! :D Now, lets have the variables define the objects. What I mean by define is set the variable to the (or a) value/ object.

local zeScriptsParent = script.Parent
local zeScriptsParentParent = zeScriptsParent.Parent
local zeFrameGui = zeScriptsParentParent:WaitForChild('Frame1')
-- WAITFORCHILD AT WORK!!! >>:O
local zeMainGui = zeScriptsParentParent:WaitForChild('Main')
-- That got dramatic e-e

script.Parent.MouseButton1Click:Connect(function()
    script.Parent.Parent.Frame1.Visible = true
    script.Parent.Parent.Main.Visible = false
end)

And that's all! :D Now, lets all get on with our lives...

WAIT!

What?

What was the point of adding the variables if you weren't going to use them?!

Good point. Lets do that right now!

Lets replace the direct-things in the original code with the variables, because why waste them? :D

local zeScriptsParent = script.Parent
local zeScriptsParentParent = zeScriptsParent.Parent
local zeFrameGui = zeScriptsParentParent:WaitForChild('Frame1')
local zeMainGui = zeScriptsParentParent:WaitForChild('Main')

zeScriptsParent.MouseButton1Click:Connect(function()
    -- There, I added the variable! :D
    script.Parent.Parent.Frame1.Visible = true
    script.Parent.Parent.Main.Visible = false
end)

There we go! All finished now! :D Now I'll go get lunch...

YOU STILL DIDN'T USE ALL OF THEM!!

Fine, Mr. Picky! T-T

Lets apply the rest real quick...

local zeScriptsParent = script.Parent
local zeScriptsParentParent = zeScriptsParent.Parent
local zeFrameGui = zeScriptsParentParent:WaitForChild('Frame1')
local zeMainGui = zeScriptsParentParent:WaitForChild('Main')

zeScriptsParent.MouseButton1Click:Connect(function()
    zeFrameGui.Visible = true
    -- Because the variable has defined the object, you're able to access the object that way, and prevent errors if the object were to somehow "disappear." >.>
    zeMainGui.Visible = false
end)

Happy now..?

Yes, thank you sweety. c;

Ok... o-o

Stuffed touched on, but didn't go into great detail about ~~ Attempt to index "information" (a nil value) ~~

C'mon, not this again! T-T Lets try this instead.

Junk talked about, explained and already has links but adding them here anyway

  1. TextButtons

  2. ImageButtons

  3. The WaitForChild Function

  4. Variables

IT WORKED!!! :O

Hope this helped you in any way! :D

Ad
Log in to vote
-2
Answered by 7 years ago

What are you trying to make invisible? and are you sure the function is being called?

2
Inquiries like this are meant for comments. Unless you're supplying a solution, don't answer. Goulstem 8144 — 7y
0
He joined 3 days ago, i'm sure it was to help here. x3 Ap_inity 112 — 7y

Answer this question