How do I tween a frame to do this?

Okay so what i want is for this to work

local Tier2NeededXP = 10

So every time the player gets 1+ XP or something the frame size tweens closer to the end, Until when “Tier2NeededXP” = 0 then the tween resets

Any idea on how to do this?
thank you :slight_smile:

You should use an IntValue for this because the :GetPropertyChangedSignal event will make your life a lot easier and your code faster.

local TweenService = game:GetService("TweenService")
local _TweenInfo = TweenInfo.new(...)

local ExpNeeded = ... (IntValue)
local MaxExpNeeded = ...
local ProgressBar = ...
local MaxProgressBarSizeX = ...
local Unit = MaxProgressBarSizeX / MaxExpNeeded
local PreviousValue = ExpNeeded.Value

ExpNeeded:GetPropertyChangedSignal("Value"):Connect(function()
  if ExpNeeded.Value < PreviousValue then
    TweenService:Create(ProgressBar, _TweenInfo, 
      {Size = ProgressBar.Size + Udim2.new(0, Unit, 0, 0)}):Play()
  elseif ExpNeeded.Value == 0 then
    ProgressBar.Size = Udim2.new(0, 0, 0, 0)
  end

  PreviousValue = ExpNeeded.Value
end)

Now you’ll need to fill in the blanks (...) with the appropriate values/objects, and this should work.

1 Like

Could you explain more on what some of that means? Cause right now there is no notes and im just trying to figure it out on my own

My bad, I should’ve explained it better. So what it does is it basically has a MaxSize and a MaxExp value, which gives us the Unit of increment (the amount to add to the size when the needed exp decrements). And after that it’s pretty straight forward, we observe the change in the CurrentExp and check if it is less than the previous exp, if so, we make the bar larger by 1 Unit, if the CurrentExp is 0 then we make the bars size 0. I hope I explained it well.

Im not the most advanced in this area, So on the

local MaxProgressBarSizeX =

What do I place at the end of =? Cause what I did was place “0.542” Which is the end of the frame

It should be Bar.Size.X.Offset

I Use scale for my UI would that matter?

Well you’ll have to change the code to account for that, so here you go:

local TweenService = game:GetService("TweenService")
local _TweenInfo = TweenInfo.new(...)

local ExpNeeded = ... (IntValue)
local MaxExpNeeded = ...
local ProgressBar = ...
local MaxProgressBarSizeX = ...
local Unit = MaxProgressBarSizeX / MaxExpNeeded
local PreviousValue = ExpNeeded.Value

ExpNeeded:GetPropertyChangedSignal("Value"):Connect(function()
  if ExpNeeded.Value < PreviousValue then
    TweenService:Create(ProgressBar, _TweenInfo, 
      {Size = ProgressBar.Size + Udim2.new(Unit, 0, 0, 0)}):Play()
  elseif ExpNeeded.Value == 0 then
    ProgressBar.Size = Udim2.new(0, 0, 0, 0)
  end

  PreviousValue = ExpNeeded.Value
end)

Now you can make it Bar.Size.X.Scale

0:

It seems to be working! Ill play around with it a bit more and then ill mark your post as the solution!

Thanks! :slight_smile:

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