Returning Values Not Used

I am writing a script to sell a value, momentum, into coins. 10 momentum = 1 coin, and here is the script I have to check to make sure that their value is >= 10;

Script
local leaderstats = Plr.leaderstats

if leaderstats.Momentum.Value >= 10 then

leaderstats.Coins.Value = leaderstats.Coins.Value + leaderstats.Momentum.Value / 10

leaderstats.Momentum.Value = 0

end

end)

However if the player has, let’s say, 11 momentum then they receive only 1 coin and lose that 1 momentum. Is there any way I can return the singles digit of the momentum to the player so that they don’t lose that momentum?

Got it working. I basing it off of Qxest’s reply I rewrote the script. Here it is now for anyone wondering;
Edit 2; small bug in the updated script, I just fixed it quickly

Working Script
local leaderstats = Plr.leaderstats

if leaderstats.Momentum.Value > 10 then

Val = leaderstats.Momentum.Value%10

leaderstats.Coins.Value = leaderstats.Coins.Value + Val

leaderstats.Momentum.Value = Val

end

end)

You may be looking for the modulus operator (%). If you have 10 coins, the remainder of 10%10 == 0, if 11%10 == 1, and so on. The modulo operator returns the remainder of the whatever two numbers you provided.

1 Like

I’ll give it a go! thanks for the help, I’ll let you know if this works

Still having the same problem, it doesn’t seem to be returning the momentum. Would just changing the / 10 in the script to % 10 be enough or would I have to add more to the script?

Got it working