so im currently trying to tween a value thats a string but everytime it runs i get
TweenService:Create property named ‘Value’ on object ‘Value’ is not a data type that can be tweened
im not entirely sure how im supposed to be doing this but, im creating a variable to read the cash value before the number changes, and then another for what the value is after the player sells something, I would like to have the stringvalue that was created to be tweened to start at the old value and smoothly climb up to the new value, I plan on using this value as a text display somewhere in a gui but for now I need to make sure it works
game.ReplicatedStorage.Leaderboard.Sell.OnServerEvent:connect(function(player)
local lstats = player:WaitForChild("lstats")
local cash = player.lstats.Cash.Value
local tweenInfo = TweenInfo.new(3)
local Casher = Instance.new("StringValue")
Casher.Parent = player.lstats
Casher.Value = player.lstats.Cash.Value
print(Casher.Value)
player.lstats.Cash.Value += player.lstats.Ore.Value
local cash2 = player.lstats.Cash.Value
local goal = {}
goal.Value = cash2
TweenService:Create(Casher, tweenInfo, goal):Play()
player.lstats.Ore.Value = 0
end)
You cannot interpolate string values, nor should you try (it’s impractical).
Instead, tween a number value that will later convert to a string. If you have, 1000 cash, then a number value should tween to 1000 as a number, not as a string.
Firstly, as already noted, you cannot tween a string value. But presumably your ‘cash’ is a number, and instead you’d use a NumberValue instead, which can be tweened.
If you want to use this in a UI, you would need to update your TextLabel every frame to show the tweening of the number because it would not update automatically from the NumberValue. With this, if needed, you can convert it into a string and append any other strings ie. £ or $ or ‘Cash’. I think that’s what you intend to do.
Unfortunately, the only way to tween a number is with a NumberValue or IntValue. You would use an IntValue behind the scenes, to tween the cash value, and then update the stats string value every frame.
I also don’t understand what you mean by the limitations of NumberValue. Plus, if you want to store a cash value in the player, ideally you’d leave it as a number, and then any code that uses it would convert it into a string, or is that because of the ‘limitations’?
The code snippet mentions cash, and so I assumed they wanted to tween the cash (number) portion of the string. Lerping from (ex.) 10 → 100 is possible.
Store it as an base 10, one decimal part and one exponent part.
{
value = 1.39,
exponent = 10
}
-- This would then be interpreted as 1.39 * 10^10
Alternatively, store it as a string “1.39e10”, which would be the same as the above. You may then tween each portion of the number independently. (Translate the e^10 to appropriate shortening [such as qn])
I’m having the same issue, But in my case I’m using BigNum to store bigger numbers but this makes me unable to tween it? I cannot use numbers since the numbers are too big to be stored