So there is a glitch that goes like this:
Balance: $100
Buys Item: -$10
Balance: $90
Buys Item: -$50
Balance: $40
Earns $10
Game says + $70
What?
Balance: $110
If that wasn't a good enough explanation here's this. Whenever I buy something, then earn money through some way, I basically gain back all the money I had plus the money I earned so basically I never lose any money, and that's a problem.
Here's the script that I use to change the money values:
local plr = game.Players.LocalPlayer
local cash = plr:WaitForChild("leaderstats"):WaitForChild("Cash")
local previouscash = cash.Value
local addition = script.Parent:WaitForChild("Addition")
local function comma(input)
local a, b = string.match(input, "(%d+)(%.?%d*)")
return string.reverse(a):gsub("(%d%d%d)", "%1,"):gsub(",$", ""):reverse() .. (b or "")
end
cash.Changed:connect(function()
-- script.Parent.Sound:Play()
if tonumber(cash.Value) <= tonumber(previouscash) then
local difference = previouscash - cash.Value
addition.Text = ("-" .. comma(difference))
addition.FontSize = Enum.FontSize.Size48
previouscash = cash.Value
wait(0.1)
addition.FontSize = Enum.FontSize.Size24
wait(1.9)
addition.Text = ""
elseif tonumber(cash.Value) > tonumber(previouscash) then
local difference = cash.Value - previouscash
addition.Text = ("+" .. comma(difference))
addition.FontSize = Enum.FontSize.Size48
previouscash = cash.Value
wait(0.1)
addition.FontSize = Enum.FontSize.Size24
wait(1.9)
addition.Text = ""
end
script.Parent.Text = ("$" .. comma(cash.Value))
end)
while wait() do
script.Parent.Text = ("$" .. comma(cash.Value))
end

1 comment
"previouscash" is the same value as "cash". So I suggest adding another IntValue to indicate the previous cash.