IntValue How much Changed?

Hello! I’m Trying to make a Text on the Screen what displays how much Coins you just got (No Leaderboard ) If I do

    game.Players.LocalPlayer.Currency.Coins.Changed:Connect(function(v)
    script.Parent.Text = v
    end)

It will show the Value. But not how much changed! I wan’t it to be like I have 23 Coins and if you get 1 Coin The Text Says (1) Instead of 24! Is there any way to detect this? And This should be an IntValue!

You need to keep track of the previous value, and then subtract one from the other to get the difference.

local lastCoins = 0

game.Players.LocalPlayer.Currency.Coins.Changed:Connect(function (coins)
    local difference = coins - lastCoins
    script.Parent.Text = difference
    lastCoins = coins
end)
1 Like
local current = 0
game.Players.LocalPlayer.Currency.Coins.Changed:Connect(function(v)
    script.Parent.Text = v - current
    current = script.Parent.Text
end)

Ok If It works I’m gonna ping this as a Solution!

This does not work:

  1. You cast an integer to a string and then assign it to a value that should be an integer potentially resulting in erroneous behavior.
  2. You assign the value of current to the difference between the new value and the current value. This will work correctly the first time Coins changes, but every subsequent change will be wrong.
1 Like

Yeah you’re right didn’t think about that

1 Like

Yep! Works Fine!! Thanks :slight_smile: