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

Why wont my script that should close a GUI close?

Asked by 6 years ago
Edited 6 years ago

This is weird... No errors in the dev console.. and nothing in the script...... and this is in a local script, if that helps anything

Any help? My code:

local frame = script.Parent.Parent.key_frame
local button = script.Parent
local textOpen = "SHOW ANIMATION KEYS"
local textClose = "HIDE ANIMATION KEYS"

if frame.Parent.key_show_hide_btn.Text == textOpen then
    button.MouseButton1Down:connect(function()
    frame.Visible = true
    button.Text = textClose
    end)
elseif
    frame.Parent.key_show_hide_btn.Text == textClose then
    button.MouseButton1Down:connect(function()
        frame.Visible = false
        button.Text = textOpen
    end)
end

0
Does everything exists? ILikeTofuuJoe 1 — 6y

3 answers

Log in to vote
1
Answered by 6 years ago
Edited 6 years ago
local frame = script.Parent.Parent.key_frame
local button = script.Parent
local textOpen = "SHOW ANIMATION KEYS"
local textClose = "HIDE ANIMATION KEYS"

button.MouseButton1Down:Connect(function()
    if frame.Parent.key_show_hide_btn.Text == textOpen then
        frame.Visible = true
        button.Text = textClose
    elseif frame.Parent.key_show_hide_btn.Text == textClose then
        frame.Visible = false
        button.Text = textOpen
    end
end)

The way you had it set up, if the text = textOpen when the game runs then it'll just change it to textClose every time you click it

0
Explain what you changed in the script or people will never learn. M39a9am3R 3210 — 6y
Ad
Log in to vote
0
Answered by 6 years ago

Try.

local frame = script.Parent.Parent.key_frame
local frameText = script.Parent.Parent.key_show_hide_btn.Text
local button = script.Parent
local textOpen = "SHOW ANIMATION KEYS
local textClose = "HIDE ANIMATION KEYS"

if frameText == textOpen then
    button.MouseButton1Down:connect(function()
    frame.Visible  = true
    button.Text = textClose
    frameText == textClose
elseif frameText == textClose then
    button.MouseButton1Down:connect(function()
    frame.Visible = false
    button.Text = textOpen
    frameText == textOpen

Check it if it works.

Log in to vote
0
Answered by 6 years ago

No. No. Do NOT have end with ) inside of ends WITHOUT. ITS UGLY AND UNPROFESSIONAL

    end) -- ????????
end

And you didn't have to do all that checking if it was visible or not.

local openTxt = "SHOW ANIMATION KEYS"
local closeTxt = "HIDE ANIMATION KEYS"

script.Parent.MouseButton1Click:Connect(function() -- Connect not connect
    script.Parent.Parent.key_frame.Visible = not script.Parent.Parent.key_frame.Visible -- Changes the current visible state to its opposite. Make sure the TextButton is not in the frame.
    if script.Parent.Parent.key_frame.Visible == true then
        script.Parent.Text = closeTxt
    else
        script.Parent.Text = openTxt 
    end
end)
0
You don't need the `== true` part theCJarmy7 1293 — 6y

Answer this question