Tweening Doesn't Work After 2nd Time

Hello, I had this problem, but I don’t know how to explain, so here’s a video.

FYI, I’m very new to scripting.


When I try to press the button again, it doesnt go down like it did the first time i pressed it.

Here’s the code for it:

local button = script.Parent
	local gui = script.Parent.Parent
local TweenSvc = game:GetService("TweenService")

if button.Rotation == 0 then
	button.Activated:Connect(function()
	gui:TweenPosition(UDim2.fromScale(0.5,1.085), "In", "Back", 1, false,  function() --reg pos {0.5, 0},{0.918, 0} done pos {0.5, 0},{1.085, 0}
		TweenSvc:Create(button, TweenInfo.new(1), {Rotation = 180}):Play()
		
		if button.Rotation == 180 then
			button.Activated:Connect(function()
				gui:TweenPosition(UDim2.fromScale(0.5, 0.918), "Out", "Back", 1, false, function()
					TweenSvc:Create(button, TweenInfo.new(1), {Rotation = 0}):Play()
				end)
			end)
		end
		
	end)

end) 

end


and theres no errors for it, so if you see something im doing wrong, please let me know. Thank you!

Try adding print()in the script so that we are able to find the issue more easily

1 Like

Is the button rotation equal to 180. If there are errors send them and try putting a print after the if statement checking if the rotation is equal to 180.

1 Like

Wait never mind. Are you making sure you are running the code after you click it again?

1 Like

ahh is that what you’re supposed to do? i am not sure how to do that, it would be great if you could tell me maybe? thank you!

okay! thank you, ill do that rn!

Love the UI man could I have some advice on mine?

1 Like

sure! send it over! ill give some tips and maybe some assets? :wink:

Before you put the if statements put the button activated before it then run the if statement and put them in two different functions.

1 Like

Your code is very prone to memory leaks because button.Activated is constantly being connected (but not disconnected), and the initial problem lies in a logic error.
The following code should function more properly: (using only tweenservice, because I’m not familiar nor do I condone :TweenPosition)

local button = script.Parent
local gui = button.Parent
local TweenSvc = game:GetService("TweenService")
local closed = false -- switch

local close_PosInfo = TweenInfo.new(1,Enum.EasingStyle.Back,Enum.EasingDirection.In)
local close_PosGoal = {Position = UDim2.fromScale(0.5,1.085)}
local close_RotInfo = TweenInfo.new(1)
local close_RotGoal = {Rotation = 180}

local open_PosInfo = TweenInfo.new(1,Enum.EasingStyle.Back,Enum.EasingDirection.Out)
local open_PosGoal = {Position = UDim2.fromScale(0.5, 0.918)}
local open_RotInfo = TweenInfo.new(1)
local open_RotGoal = {Rotation = 0}
button.Activated:Connect(function()
	if closed then
		closed = false
		TweenSvc:Create(gui,close_PosInfo,close_PosGoal):Play()
		task.wait(1)
		TweenSvc:Create(button,close_RotInfo,close_RotGoal):Play()
	else
		closed = true
		TweenSvc:Create(gui,open_PosInfo,open_PosGoal):Play()
		task.wait(1)
		TweenSvc:Create(button,open_RotInfo,open_RotGoal):Play()
	end
	-- Can use debounce to prevent button spamming (but personally, I prefer more responsive UIs)
end)
2 Likes

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.