A new small problem with tween

  1. What do you want to achieve? Keep it simple and clear!
    I wanna make button tween positon of gui twice, like open & close thing.
  2. What is the issue? Include screenshots / videos if possible!
    Idk why but my second script to open don’t work so i have no idea why
  3. What solutions have you tried so far? Did you look for solutions on the Developer Hub?
    i tryed to add loops, but that lags a studio a lot. No i didn’t.
    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,1.803, 0),"Out","Sine",2,false)
	Mission1:TweenPosition(UDim2.new(0.05, 0,1.803, 0),"Out","Sine",2,false)
	buttonGUI:TweenPosition(UDim2.new(0.781, 0,0.895, 0),"Out","Sine",2,false)
	clicks = clicks + 1
	while Image.Rotation <= 269 do
		Image.Rotation = Image.Rotation + 10
		wait(0.01)
	end
	end)
	end
if clicks == 1 then
button.MouseButton1Click:Connect(function()
	Bar:TweenPosition(UDim2.new(-0.002, 0,0.803, 0),"Out","Sine",2,false)
	Mission1:TweenPosition(UDim2.new(0.05, 0.924, 0),"Out","Sine",2,false)
		buttonGUI:TweenPosition(UDim2.new(0.781, 0,0.699, 0),"Out","Sine",2,false)
		clicks = clicks - 1
	while Image.Rotation <= 89 do
		Image.Rotation = Image.Rotation - 10
		wait(0.01)
	end
	end) 
	end

Sorry for bumping, just like i think that’s easy thing and i’m stupid, and it’s fixable in few seconds

try to wrap the loop in a coroutine so it doesn’t halt the whole script

wait(0.01) is the same as wait() since the shortest length of time a wait() command can yield for is 1/60th of a second which is 0.0166… seconds.

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,1.803, 0),"Out","Sine",2,false)
		Mission1:TweenPosition(UDim2.new(0.05, 0,1.803, 0),"Out","Sine",2,false)
		buttonGUI:TweenPosition(UDim2.new(0.781, 0,0.895, 0),"Out","Sine",2,false)
		clicks = clicks + 1
		task.spawn(function()
			while Image.Rotation <= 269 do
				Image.Rotation = Image.Rotation + 10
				task.wait()
			end
			return
		end)
	end)
end

if clicks == 1 then
	button.MouseButton1Click:Connect(function()
		Bar:TweenPosition(UDim2.new(-0.002, 0,0.803, 0),"Out","Sine",2,false)
		Mission1:TweenPosition(UDim2.new(0.05, 0.924, 0),"Out","Sine",2,false)
		buttonGUI:TweenPosition(UDim2.new(0.781, 0,0.699, 0),"Out","Sine",2,false)
		clicks = clicks - 1
		task.spawn(function()
			while Image.Rotation <= 89 do
				Image.Rotation = Image.Rotation - 10
				task.wait()
			end
			return
		end)
	end) 
end

You will likely need to add a debounce to prevent the functions from executing too much. Read more here: