Gui Tweening Help

  1. What do you want to achieve? Keep it simple and clear!
    Hi there, is there any way to tween a gui from a start place to an end. I know this is entirely possible
    using values for position, but how would I do it without having to do that. e.g have a tween run from one frame to another.

  2. What is the issue? Include screenshots / videos if possible!
    I’m unsure on how to tween it without the use of position values.

  3. What solutions have you tried so far? Did you look for solutions on the Developer Hub?
    Couldn’t find anything on how to do this.

Basically, I’m trying to tween a frame to another frame, without saying Udim2.new, etc. I know this is
probably has a easy solution, but any help would be greatly appreciated! Thanks :smile:

Here is my absolute awful coding – as a bonus it would be really helpful if you can point out ways to make the code more efficient and optimisable. Of course it’s not required.

-- local tweenservice = game:GetService("TweenService")
local player = game.Players.LocalPlayer
local Frame = script.Parent.Parent.Parent:WaitForChild("Frame")
local TrophyFrame = script.Parent.Parent:WaitForChild("Trophies")
local TrophyIndicator = script.Parent:WaitForChild("TrophyIndicator") -- This is the frame that changes position upon trophy amount 
-- Also the frame that is used for tweening.
local TrophyLabel = script.Parent.Parent:WaitForChild("TrophyLabel")

-- Trophies
local Beginner = script.Parent:WaitForChild("BeginnerLeague")
local Bronze = script.Parent:WaitForChild("BronzeLeague")
local Silver = script.Parent:WaitForChild("SilverLeague")
local Gold = script.Parent:WaitForChild("GoldLeague")
local Adamant = script.Parent:WaitForChild("AdamantLeague")
local Ruby = script.Parent:WaitForChild("RubyLeague")
local Diamond = script.Parent:WaitForChild("DiamondLeague")
local Mythical = script.Parent:WaitForChild("MythicalLeague")

while wait() do
	
if player.leaderstats.Trophies.Value == 100  or player.leaderstats.Trophies.Value < 249 then
				print("Beginner reached")
				TrophyIndicator.Position = Beginner.Position - UDim2.new(0,0,-0.35,0) 
         -- The code above is what I'm trying to tween from position 'A' to position 'B', without having to use values.
		TrophyIndicator.AnchorPoint = Vector2.new(0,0,0.5,0)
				TrophyIndicator.Visible = true
				TrophyLabel.Text = "Congratulations, you are in Beginner League!"
				
			
		else
			if player.leaderstats.Trophies.Value == 250  or player.leaderstats.Trophies.Value < 499 then					
				print("Bronze reached")
				TrophyIndicator.Position = Bronze.Position - UDim2.new(0,0,-0.35,0)
				TrophyIndicator.AnchorPoint = Vector2.new(0,0,0.5,0)
			   	TrophyIndicator.Visible = true
				TrophyLabel.Text = "Congratulations, you are in Bronze League!"

		
		else
			if player.leaderstats.Trophies.Value == 500  or player.leaderstats.Trophies.Value < 999 then
				print("Silver reached")
				TrophyIndicator.Position = Silver.Position - UDim2.new(0,0,-0.35,0)
				TrophyIndicator.AnchorPoint = Vector2.new(0,0,0.5,0)
				TrophyIndicator.Visible = true
				TrophyLabel.Text = "Congratulations, you are in Silver League!"

		else
			if player.leaderstats.Trophies.Value == 1000  or player.leaderstats.Trophies.Value < 1499 then
				print("Gold reached")
				TrophyIndicator.Position = Gold.Position - UDim2.new(0,0,-0.35,0)
				TrophyIndicator.AnchorPoint = Vector2.new(0,0,0.5,0)
				TrophyIndicator.Visible = true	
				TrophyLabel.Text = "Congratulations, you are in Gold League!"
					
		else
			if player.leaderstats.Trophies.Value == 1500  and player.leaderstats.Trophies.Value < 1999 then
				print("Admant reached")
				TrophyIndicator.Position = Adamant.Position - UDim2.new(0,0,-0.35,0)
				TrophyIndicator.AnchorPoint = Vector2.new(0,0,0.5,0)
				TrophyIndicator.Visible = true
				TrophyLabel.Text = "Congratulations, you are in Adamant League!"

		else		
			if player.leaderstats.Trophies.Value == 2000  and player.leaderstats.Trophies.Value < 2499 then
				print("Ruby reached")
				TrophyIndicator.Position = Ruby.Position - UDim2.new(0,0,-0.35,0)
				TrophyIndicator.AnchorPoint = Vector2.new(0,0,0.5,0)
				TrophyIndicator.Visible = true
				TrophyLabel.Text = "Congratulations, you are in Ruby League!"

		else		
			if player.leaderstats.Trophies.Value == 2500 and player.leaderstats.Trophies.Value < 2999 then
				print("Diamond reached")
				TrophyIndicator.Position = Diamond.Position - UDim2.new(0,0,-0.35,0)
				TrophyIndicator.AnchorPoint = Vector2.new(0,0,0.5,0)
				TrophyIndicator.Visible = true
				TrophyLabel.Text = "Congratulations, you are in Diamond League!"

		else			
			if player.leaderstats.Trophies.Value >= 3000 then
				print("Mythical reached")
				TrophyIndicator.Position = Mythical.Position - UDim2.new(0,0,-0.35,0)
				TrophyIndicator.AnchorPoint = Vector2.new(0,0,0.5,0)
				TrophyIndicator.Visible = true	
				TrophyLabel.Text = "Congratulations, you are in Mythical League!"

									
								end
							end
						end
					end	
			
				end
				
			end
		end
	end
end
1 Like

Well, Its really simple. You can tween the gui to DestinationFrame.Position

Here read up on this and I I know it will help, usually when I’m tweening guis I platform it like this

local Gui -- keeps this blank and out of the function

local function Tween()
Gui = -- the gui your trying to edit

Gui:TweenPosition(UDim2.new(1,0,1,0), nil, nil, 0.5) -- O.5 is the time, the four 0's are the x and y scale and offset(Change scale, they are the ones that are numbered) and nil is just the animation types but you can keep them false
end
1 Like

Yes, I looked into that before, but how would I go about not repeating this code each time for each tween?

You can create function for tweening

I edited my code, if you are using the same tween position just make a function if not do it manually, also reediting is it will work with more than one tween, rq.

No you can add a position parameter to the function and that will solve the problem

Yes, that works but I’m wondering how I would tween it without using the positions. For example do I have to use Udim2 values, or can tween from a frame to another frame?

I said that you can use destinationFrame.Position

So what you are trying to achieve is instead of doing a UDim2 value, you will have another GUI that is the goal position? If so, yes, you just have to define the position of the frame goal.

Frame1.Position = Frame2.Position

This can be tweened.

Ok, thanks for your help I’ll see if I can do that.

Yes, that’s what I was trying to do instead of having to set the frame positions manually.

1 Like