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
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.
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.
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
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)