π΅ Currency
This module is one of the most useful modules in the entire framework.
It allows you to create and modify currency.
Creating a currencyβ
To create a currency, require the framework and do the following:
local Framework = require(path.to.framework).GetServer()
local Currency = Framework.Currency
Currency.Create("Wins", "rbxassetid://14647075582", Color3.new(1, 0.73, 0))
There are a couple rules when creating currency:
- The name is required
- If you do not specify an image, it won't create any UI
- If you do not specify a colour, it will be created on the sidebar below the menu buttons.
When you have finished creating your currencies, you MUST use the Finalsie method, otherwise it will not create the currencies
Currency.Finalise()
Do not use the BEFORE you finish creating all the currency, its common sense come on i don't gotta explain why.
Modifying a currencyβ
To modify a currency, you first need to get the currency:
-- assuming you already have the player defined as 'player'
local Framework = require(path.to.framework).GetServer()
local Currency = Framework.Currency
local playerCurrency = Currency.Get(player, currencyName)
BindToUpdateβ
This can only be used on server side scripts / modules
BindToUpdate fires a BindableEvent once the currency has been updated.
playerCurrency:BindToUpdate(function()
-- do things here, like grabbing new values.
end)
GetMultipliersβ
This returns the multipliers that have been applied to the currency such as:
- Pets
- Trails
- Potions
- Friend Boost
local multipliers = playerCurrency:GetMultipliers()
print(multipliers) -- e.g. 5
Encodeβ
Bignum dictionary -> readable string
local encoded = playerCurrency:Encode()
GetValueβ
Returns the stored bignum
local Bignum = playerCurrency:GetValue()
CanAffordβ
This method returns a boolean which tells you whether a player can afford something.
This does NOT remove currency
local canAfford = playerCurrency:CanAfford(500)
if canAfford then
print("Can afford")
else
print("Can't afford")
end
AttemptPurchaseβ
Like CanAfford, this returns a boolean if the player can afford something, however, this one DOES remove currency.
This acts like a shop system, for example, when a player clicks to buy something, you can check whether it goes through or not.
local hasPurchased = playerCurrency:AttemptPurchase(500)
if hasPurchased then
print("Has Purchased")
else
print("Hasn't Purchased")
end
GetStoredβ
Returns the stored value of the currency
print(playerCurrency:GetStored())
GetRealAmountβ
Difficult to explain, but this method gives you a number when all multipliers have been applied.
local number = 10
local numberWithMultipliers = playerCurrency:GetRealAmount(number)
Setβ
This sets the currency to a number, multipliers are not applied.
playerCurrency:Set(100)
Multiplyβ
This multiplies the current stored data.
playerCurrency:Multiply(10) -- 10x
Divideβ
Does the opposite of multiply
playerCurrency:Divide(10) -- / 10
Addβ
Adds an amount to the currency
You can specify whether you apply multipliers or not, but bare in mind, not specifying automatically denies the use of multipliers.
playerCurrency:Add(10) -- no multipliers
playerCurrency:Add(10, false) -- no multipliers
playerCurrency:Add(10, true) -- multipliers
Subtractβ
Subtracts an amount from the currency, multipliers are not used in this method at all.
playerCurrency:Subtract(100)
Raiseβ
Exponentiates the amount with the supplied exponent
playerCurrency:Raise(10) -- amount ^= 10