How to see how much the value has changed?

so i’m trying to make a 2x exp gamepass, but to do that i want see how much the value has changed , it should be like (NewVal-OldVal) and double that amount i’ve tried some stuff but couldnt make it work any help please?

If all you’re trying to do is double earned XP, it might be easier to create a module function or something, like Give_XP, and from there you can implement logic to determine if a player has the gamepass, then just double whatever value was passed in as an argument.


local mps = game:GetService("MarketplaceService")
local gamepass_ID = 0

function Give_XP(xp, player) 
    local xp_to_give = (mps:UserOwnsGamePassAsync(player.UserId, gamepass_ID) and xp * 2) or xp
    --do stuff with xp_to_give

Original value:

local original =
--if its in a datastore, save the original before you apply 2x

New Value:

local new = -- updated

simple logic man

yeah i would like to do that but i got like a thousand scripts i was wondering if there was an easier way

1 Like

Not simple logic because this doesn’t answer the question at all. It’s not useful. OP is looking to see how much a value has changed in order to implement a 2X EXP game pass, so indexing the value would be pointless. If you had the inclusion of when these values would be applicable (as in subtracting the old from the new), then sure, though that isn’t a viable solution. You need to account for new levels which decrement EXP.

This seems representative of an XY problem though. When you’re implementing a 2X EXP game pass, you need to double the receiving amount and then distribute it to the player, not find out the change and then add that back. It introduces unnecessary complexity to your code.

@C_Sharper’s method is the way to go - ideally, you will want a way to determine when the server should be giving a player EXP, so rather than raw-writing to a player’s EXP value you should facilitate the work through a function or BindableEvent. When the function receives the EXP value to give as an argument, check if the player has the 2X EXP game pass. If they do, multiply the value by two, then add it to the player’s EXP amount.


yes i know, but as i’ve stated before i’ve got a ton of scripts to fix if that’s what im gonna do , i was looking for a more efficient way