Tween not working as exspected

Hi,

I am trying to animate a gui to go from a random position and then tween up a bit, below is what I have so far but when the gui goes up it also goes to the left a bit as well which I can’t understand why?

local startPosition = UDim2.new(math.random(2,7) / 10,0,math.random(2,7) / 10,0)
local targetPosition = UDim2.new(startPosition.X.Offset, 0, startPosition.Y.Offset - 5, 0)
1 Like

Could you share the tween call?

1 Like

Can I ask why you are using the offset for the target position? Why not use the scale?

1 Like

Hi,

I got working using scale, below is the working code, the Frame goes stright up and starts to fade.

-- Varibles
local PlayerGui = game:GetService("Players").LocalPlayer:WaitForChild("PlayerGui")
local TweenService = game:GetService("TweenService")
local ScreenGui = PlayerGui:WaitForChild("ScreenGui")
local CoinFrame = ScreenGui:WaitForChild("CoinFrame")

-- GUI Position
local startPosition = UDim2.new(math.random(2,7) / 10,0,math.random(2,7) / 10,0)
local targetPosition = UDim2.new(startPosition.X.Scale, 0, startPosition.Y.Scale - 0.10, 0)

-- Clone Frame
local cloned = CoinFrame:Clone()
cloned.Parent = ScreenGui
cloned.Position = startPosition

-- Setup TweenInfo
local tweenInfoPosition = TweenInfo.new(2)
local tweenInfoTransparency = TweenInfo.new(1)

-- Define Tweens
local tweenFrame = TweenService:Create(cloned, tweenInfoPosition, {Position = targetPosition})
local tweenImage = TweenService:Create(cloned.Image, tweenInfoTransparency, {ImageTransparency = 1})
local tweenText = TweenService:Create(cloned.Text, tweenInfoTransparency, {TextTransparency = 1})

--Play Tweens
tweenFrame:Play()
tweenImage:Play()
tweenText:Play()
1 Like

So is the problem fixed? If it is, make sure to mark this topic as solved so it can close.

If you have any other questions about it just let me know :slight_smile:

1 Like