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

What is wrong with this text button script?

Asked by
Mystdar 352 Moderation Voter
10 years ago

This script is supposed to make a GUI visible is it is not, or invisible if it is. It is a normal script inside a frame, inside a TextButton, inside a ScreenG UI inside the Starter GUI.

local button = script.Parent.Parent
local frame = script.Parent
function onMouseButton1Down()
    --Hide the entire frame, don't remove it!
            if frame.Visible == false then
            frame.Visible = true
            if frame.Visible == true then
            frame.Visible = false
        end
    end
end
button.MouseButton1Down:connect(onMouseButton1Down)

Would it be better to make it elseif instead of he second if? Please include code in your answer. Thanks.

2 answers

Log in to vote
0
Answered by
RedCombee 585 Moderation Voter
10 years ago

You're putting an if statement inside the other if statement. Fixed:

local button = script.Parent.Parent
local frame = script.Parent
function onMouseButton1Down()
    --Hide the entire frame, don't remove it!
            if frame.Visible == false then
            frame.Visible = true
        elseif frame.Visible == true then
            frame.Visible = false
            end
end
button.MouseButton1Down:connect(onMouseButton1Down)
Ad
Log in to vote
1
Answered by
Spectrobz 140
10 years ago

That would be better :

local button = script.Parent.Parent
local frame = script.Parent
function onMouseButton1Down()
            if frame.Visible == false then
            frame.Visible = true
            elseif frame.Visible == true then
            frame.Visible = false
        end
end
button.MouseButton1Down:connect(onMouseButton1Down)

But don't do that:

            if frame.Visible == false then
            frame.Visible = true
        end
            if frame.Visible == true then
            frame.Visible = false
        end

Else your frame will turn visible and instantly turn invisible back.

0
Thanks for the clarification, I have upvoted you. Mystdar 352 — 10y

Answer this question