Title explains it all. But if you really dont get it, hopefully you can make sense by looking at my currently-not-working-jumble-of-mess code
game.Players.PlayerAdded:Connect(function(plr)
if plr.MembershipType == Enum.MembershipType.Premium then
local money = plr.leaderstats.Money :: IntValue
local curMon = money.Value
money.Changed:Connect(function(newVal)
local amountAdded = newVal - curMon
if amountAdded > -1 then
local addThis = amountAdded / 2
money.Value += addThis
print(amountAdded.." in comparison to "..addThis) -- ignore this
end
end)
end
end)
game.Players.PlayerAdded:Connect(function(plr)
if plr.MembershipType == Enum.MembershipType.Premium then
local money = plr:WaitForChild("leaderstats").Money
local curMon = money.Value
money.Changed:Connect(function(newVal)
local amountAdded = newVal - curMon
if amountAdded > 0 then
local addThis = amountAdded / 2
money.Value += addThis
end
end)
end
end)
Try this. leaderstats doesn’t get added instantly so you should probably wait for it. The :: IntValue prevented it from erroring, if it didn’t.
While I’d advice against giving premium multipliers with the intValue.Changed event. I will tell you that you forgot to update curMon whenever money.Changed is fired.
How else would I do it? My code is a pile of garbage anyways so anything else would be helpful. I’ve never really dabbled in robux related programming things.
If you want to give a multiplier to money then you would store a value that is related to the player, called MoneyMultiplier for examle then whenever you intend to add money by some means you would just multiply MoneyMultiplier to that value
Generally you store data like this in a table, but you can create a module script in replicated storage called Calculator and have a function in there that takes a number value and returns the amount you would get after all multipliers are applied to the value, making it so that you don’t have to edit every multiplier when ever you want to make a change. On top of that if you don’t use intValue.Changed you get more control as to when you actually want to give the multiplier to a user.
local mkpService = game:GetService("MarketplaceService")
local calculator = {}
local function GetMultiplier(plr: Player)
local ReturnedTable = {
["2xMoney"] = {false, 2};
["Premium"] = {false,1.5}
}
if plr.MembershipType == Enum.MembershipType.Premium then
ReturnedTable.Premium = {true, 2}
end
if mkpService:UserOwnsGamePassAsync(plr.UserId,628488827) then
ReturnedTable["2xMoney"] = {true,1.5}
end
if ReturnedTable["2xMoney"][1] and ReturnedTable.Premium[1] then
return (ReturnedTable["2xMoney"][2]+ReturnedTable.Premium[2])
end
if ReturnedTable["2xMoney"][1] then
return ReturnedTable["2xMoney"][2]
end
if ReturnedTable.Premium[1] then
return ReturnedTable.Premium[2]
end
if not ReturnedTable["2xMoney"][1] and not ReturnedTable.Premium[1] then
return 1
end
end
function calculator:Calculate(plr: Player,numberAdded: number)
local Stats = plr.leaderstats
local Money = Stats.Money
local Multiplier = GetMultiplier(plr)
Money += (numberAdded * Multiplier)
end
return calculator
local DataModule = -- Module that handles data
local calculator = {}
function calculator.Multiplier(player: Player)
local multiplier = 1
if player.MembershipType == Enum.MembershipType.Premium then
multiplier *= 1.5
end
-- Its important to cache the ownership of a gamepass as prompting
-- MarketPlaceService is much slower
if DataModule[player].Gamepasses.DoubleMoney then
multiplier *= 2
end
return multiplier
end
function calculator.MoneyGain(player: Player, money: number)
local multiplier = calculator.Multiplier(plr)
local total = money * multiplier
return total
end
return calculator