Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
✓ ANSWER ACCEPTED

Why wont my script that should close a GUI close?

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

1 comment

0

Does everything exists?

3 answers

✓ Accepted answer
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

1 comment

0

Explain what you changed in the script or people will never learn.

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.

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)

1 comment

0

You don't need the == true part

This discussion is preserved as it was. New answers, comments, and votes are closed.