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

Why doesn't my gui frame close on button click?

So whenever i click on the button to open the frame, it opens it but when i click it again it doesn't close, it opens on the first click but doesn't close on second click. I'm a very big noob at scripting and mostly use roblox scripting tutorials. In the code, "stuff" is the frame that needs to close. Here's the code

player = game.Players.LocalPlayer

human = game.Players.LocalPlayer.Character

local b = require(script.RankScript)

Open = false

function MouseClick()

if Open == false and human.Torso.roblox.Texture == b.Owner or player.userId == 75955576 then

Open = true

script.Parent.Parent.Parent.Stuff.Visible = true

elseif Open == true then

Open = false

script.Parent.Parent.Parent.Stuff.Visible = false

end

end

script.Parent.MouseButton1Down:connect(MouseClick)

1 comment

0

:connect is depreciated. use :Connect

1 answer

I changed script.Parent.MouseButton1Down:connect(MouseClick) to a script.Parent.MouseButton1Click:Connect(MouseClick)

    local player = game.Players.LocalPlayer
    
    local human = game.Players.LocalPlayer.Character
    
    local b = require(script.RankScript)
    
    Open = false
    
    local function MouseClick()
    
    if Open == false and human.Torso.roblox.Texture == b.Owner or player.userId == 75955576 then
    
    Open = true
    
    script.Parent.Parent.Parent.Stuff.Visible = true
    
    elseif Open == true then
    
    Open = false
    
    script.Parent.Parent.Parent.Stuff.Visible = false
    
    end
    
    end
    
    script.Parent.MouseButton1Click:Connect(MouseClick)

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