How do i make open & close button

  1. What do you want to achieve? Keep it simple and clear!
    I wanna make open & close button, but i don’t know what to do
  2. What is the issue? Include screenshots / videos if possible!
    I don’t know what to do
  3. What solutions have you tried so far? Did you look for solutions on the Developer Hub?
    I tryed to add loops, but didn’t help. No i didn’t
    Here is my code:
local button = script.Parent
local clicks = 0
local DB = false
local Image = script.Parent.Parent.ImageLabel
local buttonGUI = game.Players.LocalPlayer.PlayerGui.MissionsButtonCloseGUI.Frame
	local Bar = game.Players.LocalPlayer.PlayerGui.MissionsGUI.Bar
	local Mission1 = game.Players.LocalPlayer.PlayerGui.MissionsGUI.Mission1
local TweenService = game:GetService("TweenService")


if clicks == 0 then
button.MouseButton1Click:Connect(function()
		Bar:TweenPosition(UDim2.new(-0.002, 0,0.924, 0),"Out","Sine",2,false)
		Mission1:TweenPosition(UDim2.new(0.05,0, 0.803, 0),"Out","Sine",2,false)
		buttonGUI:TweenPosition(UDim2.new(0.45, 0, 0,435, 0),"Out","Sine",2,false)
		clicks = clicks - 1
	while Image.Rotation >= 91 do
		Image.Rotation = Image.Rotation - 10
		wait(0.01)
	end
	end) 
	end

This code only opens, i need to rework it for open & close

So any ideas how to do that???

button.Activated:Connect(function()
     buttonGUI.Visible = not buttonGUI.Visible -- toggle Frame visibility
end)

:sweat_smile:

1 Like
script.Parent.MouseButton1Click:Connect(function()
	if script.Parent.Parent.Visible == false then
	script.Parent.Text = "Close"
		script.Parent.Parent.Visible = true --Your button needs to be inside a frame
	else
		script.Parent.Parent.Visible = false
		script.Parent.Text = "Open"
	end
end)

Bro with tweening position lol, did u even read my post?

oh my bad i read the title as how do i make an open and close button i didnt know u wanted to tween it im so sorry

Well you’re essentially only calling the function once since the clicks value is only 0 once, with the way you’ve written it it should look something like:

local button = script.Parent
local clicks = 0
local DB = false
local Image = script.Parent.Parent.ImageLabel
local buttonGUI = game.Players.LocalPlayer.PlayerGui.MissionsButtonCloseGUI.Frame
	local Bar = game.Players.LocalPlayer.PlayerGui.MissionsGUI.Bar
	local Mission1 = game.Players.LocalPlayer.PlayerGui.MissionsGUI.Mission1
local TweenService = game:GetService("TweenService")

button.MouseButton1Click:Connect(function()
if clicks == 0 then
		Bar:TweenPosition(UDim2.new(-0.002, 0,0.924, 0),"Out","Sine",2,false)
		Mission1:TweenPosition(UDim2.new(0.05,0, 0.803, 0),"Out","Sine",2,false)
		buttonGUI:TweenPosition(UDim2.new(0.45, 0, 0,435, 0),"Out","Sine",2,false)
		clicks = clicks - 1
	while Image.Rotation >= 91 do
		Image.Rotation = Image.Rotation - 10
		wait(0.01)
	end
elseif clicks == -1 then
       Bar:TweenPosition(UDim2.new(-2, 0,0.924, 0),"Out","Sine",2,false)
		Mission1:TweenPosition(UDim2.new(-2,0, 0.803, 0),"Out","Sine",2,false)
		buttonGUI:TweenPosition(UDim2.new(-2, 0, 0,435, 0),"Out","Sine",2,false)
		clicks = 0
	while Image.Rotation >= 91 do
		Image.Rotation = Image.Rotation - 10
		wait(0.01)
	end
	end
end)
local button = script.Parent
local clicks = 0
local DB = false
local Image = script.Parent.Parent.ImageLabel
local buttonGUI = game.Players.LocalPlayer.PlayerGui.MissionsButtonCloseGUI.Frame
local Bar = game.Players.LocalPlayer.PlayerGui.MissionsGUI.Bar
local Mission1 = game.Players.LocalPlayer.PlayerGui.MissionsGUI.Mission1
local TweenService = game:GetService("TweenService")


button.MouseButton1Click:Connect(function()
	if clicks == 0 then
		clicks +=1
		Bar:TweenPosition(UDim2.new(-0.002, 0,0.924, 0),"Out","Sine",2,false)
		Mission1:TweenPosition(UDim2.new(0.05,0, 0.803, 0),"Out","Sine",2,false)
		buttonGUI:TweenPosition(UDim2.new(0.45, 0, 0,435, 0),"Out","Sine",2,false)
		clicks = clicks - 1
		while Image.Rotation >= 91 do
			Image.Rotation = Image.Rotation - 10
			wait(0.01)
		end
	elseif clicks == 1 then
		clicks -=1
		--perform whatever actions here
	end
end)