How do I make my cash text tween up to the amount from the old amount?

So I want my text to be able to tween up from an old value to a new value. For example, the old value is 0, and the new value is 10. It would go like, 0, 1, 2, 3 etc. How would I add this?

local player = game.Players.LocalPlayer
local cash = player.leaderstats.Money
local cashBalance = script.Parent

local amount = cash.Value

cashBalance.Text = "💵 "..amount

cash.Changed:Connect(function()
	amount = cash.Value
	cashBalance.Text = "💵 "..amount
end)

You probably need to have TweenService first to be able to Tween things around.

local TweenService = game:GetService("TweenService")
local TweenInfo = (Time, Enum.EasingStyle.STYLE, Enum.EasingDirection.DIRECTION) -- For ex, (2, Enum.EasingStyle.Cubic, Enum.Drection.InOut)

-- Where in TweenInfo is where your Tween's Info will be
-- You'd also need a Goal for Tween and What you will need to Tween, for example:

-- Goal
local GoalShow = {}
Goal.TextTransparency = 0 -- Change "TextTransparency" to what you want to Tween

-- The Tween
local CashTween = TweenService.new(OBJECT, TweenInfo, GoalShow) -- Where in OBJECT is replaced with your Cash's Text

-- Tween Playing
cash.Changed:Connect(function() -- Getting the script you made
	amount = cash.Value
	cashBalance.Text = "💵 "..amount 
    CashTween:Play()
end)

-- This is only a basic way how Tween works

You can check here for the TweenInfo Documentation

If you are wondering about the Different Easing Styles and Directions, you can get it here

lmk when you find it working

1 Like

Sorry if I wasn’t clear enough. something I want is more like,

It saves the old value so that it adds up to the new number by 1. Not LITERALLY tweening, thats just the word I used for it.

no worries, so simply said you want it to have a system where your cash will keep adding 1 by 1?

You’ll probably need to have more than this, and using math/addition to make it work let’s say…

local AmountEarned = Earned

repeat
    -- code here
    cashBalance.Text = "💵 "..amount + 1
    amount = amount + 1
until AmountEarned -- This will make the earning Stop at a certain Point how much they earned

You’d also need an indicator how much they earned doing that specific earnings.

Let me know if it works on your end

If you already know how to make a money system, and show it on a UI, then in that local script, instead of setting the value, you can just tween a number to that value, and continuously set it as the text, until it reaches the value.

Maybe you meant like a number spinner animation?
You could maybe check this thread from boatbomber and see if thats what you’re looking for :+1:

Ok, it works. Just not when the money goes down… How would I fix that?

You can check if the money is more or less than the money you previously had, and do the accordingly.

vice versa, if you’d want the money to go down, you’d do subtraction. Simply if you want to Buy in-game. Set up multiple Function for AmountEarned and AmountUsed

-- Both of this depends on how much the money system of your game adds/subtracts
local AmountEarned = VALUE_HERE
local AmountUsed = VALUE_HERE

function MoneyAdd()
    repeat
        -- Code Here
        -- Don't forget to do + 1
    until AmountEarned
end

function MoneySubract()
    repeat
        -- Code Here
        -- For this one, You'd use "- 1", the Negative/Subtract
    until AmountUsed
end

-- Then you would just connect these functions whenever something happen in your Game that involves with your Money System

I would suggest to check out what @BoredHelperDEV sent too, that looks so neat

@GoodGuy21938

1 Like

You can do this:

local player = game.Players.LocalPlayer
local cash = player.leaderstats.Money
local cashBalance = script.Parent

local amount = cash.Value

local tweenTime = 0.5

cashBalance.Text = "💵 "..amount

cash.Changed:Connect(function(new)
    task.spawn(function()
        local operation = new < amount and -1 or 1
        for i = 1, new, operation do
    	    cashBalance.Text = "💵 ".. i
            task.wait(tweenTime * new)
        end
    end)
    amount = new
end)

It works, but how would I make it use an instance that is already in the game?