Tweening Gui isn't working well

Hello, I have a Gui that gets tweened on when one out of 4 buttons are pressed. The Gui that is currently In the way should get tweened off and then teleported back to its original position (on the other side of the screen but not showing due to clip descendants). The issue that Im having is that the Gui gets tweened but doesn’t get teleported back and sometimes gets stuck and forgotten about in the middle of the scene.

My code:

local currFrame = EquipFrame
local ChangeDebounce = false

local function ChangeMainFrame(frame)
	if ChangeDebounce == false then
		ChangeDebounce = true
		currFrame:TweenPosition(UDim2.new(-0.5,0,0.5,0),Enum.EasingDirection.In, Enum.EasingStyle.Sine, 1)
		frame:TweenPosition(UDim2.new(0.5,0,0.5,0),Enum.EasingDirection.In, Enum.EasingStyle.Sine, 1)
		currFrame.Position = UDim2.new(-1.5,0,0.5,0)
		currFrame = frame
		ChangeDebounce = false
	end
end


Button1.MouseButton1Click:Connect(function() -- same function for other buttons but different ButtonFrame
	ChangeMainFrame(ButtonFrame)
end)
1 Like

Hey there! Your setting the denounce to true, and immediately after that you set it to false. This makes denounce not useful, make sure to add like a wait in between it, so it has time to process everything. Like this.

local currFrame = EquipFrame
local ChangeDebounce = false

local function ChangeMainFrame(frame)
	if ChangeDebounce == false then

		ChangeDebounce = true

		currFrame:TweenPosition(UDim2.new(-0.5,0,0.5,0),Enum.EasingDirection.In, Enum.EasingStyle.Sine, 1)
		frame:TweenPosition(UDim2.new(0.5,0,0.5,0),Enum.EasingDirection.In, Enum.EasingStyle.Sine, 1)
		currFrame.Position = UDim2.new(-1.5,0,0.5,0)
		currFrame = frame

        wait(1.3) -- You prob want to wait 1.3 seconds, since the tween's duration is 1 second and you want to give the script time to process

		ChangeDebounce = false

	end
end


Button1.MouseButton1Click:Connect(function() -- same function for other buttons but different ButtonFrame
	ChangeMainFrame(ButtonFrame)
end)

Tell me if this solved the problem if it didn’t get back to me.

1 Like

This fixed the issue of it getting stuck in the center of the screen but it still isn’t being moved back to the original position which is (-1.5,0,0.5,0)

1 Like

That’s odd, for me it works perfectly fine, could you send the project file? Maybe it’s something in the project itself?

ok, I had to change some things because the other file had private info on it but the file structure is the same and im still getting the same issue. I also have an Issue where if you click the button that already has the gui on screen then it will go off screen.

Tweening.rbxl (25.9 KB)

Alright, sorry for the late reaction, was busy with some other things. I rescripted it for you and it should work now. I also explained everything I did.

Tweening.rbxl (26.6 KB)

Let me know if you have any more questions and good luck with your project!

1 Like

why Enum.EasingDirection.In, Enum.EasingStyle.Sine, 1 ?
You juste need to use "In", "Sine", 1, true

This is better:

local currFrame = EquipFrame
local ChangeDebounce = false

local function ChangeMainFrame(frame)
	if ChangeDebounce == false then

		ChangeDebounce = true

		currFrame:TweenPosition(UDim2.new(-0.5,0,0.5,0),"In", "Sine", 1, true)
		frame:TweenPosition(UDim2.new(0.5,0,0.5,0),"In", "Sine", 1, true)
		currFrame.Position = UDim2.new(-1.5,0,0.5,0)
		currFrame = frame

        wait(1.3) -- You prob want to wait 1.3 seconds, since the tween's duration is 1 second and you want to give the script time to process

		ChangeDebounce = false

	end
end


Button1.MouseButton1Click:Connect(function() -- same function for other buttons but different ButtonFrame
	ChangeMainFrame(ButtonFrame)
end)

Not really, since then the script doesn’t work anymore. Look into the file, there are multiple buttons, with the script you sent you can only use one button and the bugs aren’t fixed either.

oh, then uh… use , false at the end ?
Like this
"In", "Sine", 1, false

No, that doesn’t make any sense, that wouldn’t help anything. Look into the file.

I’m pretty sure you can use both actually. It just comes down to personal preference.

1 Like

it can be a bug, and then the category need to be in #bug-reports

Uhm… It has nothing to do with bugs at all, and this is getting off-topic and confusing for the person that created this post.

Yeah that’s true. I’m sorry lol