How to make a working bank with deposits / withdraws

Hello, I’m making a game similar to that of many other RO-nation groups. With that, I want to have a working bank but I have no idea how to add a function where players can withdraw and deposit their money.

If anyone can answer my question directly, or even friend my profile on Roblox to discuss doing it for me with payment involved, that would be great.

A good way to a bank system is with metatables and metamethods Heres some sample code:

local Account = {}
Account.__index = Account --assign the __index member on the class back to itself. This is a handy trick that lets us use the class's table as the metatable for instances as well.

function Account.new(Name, Amount)
     local self = setmetatable({}, Account)
     self.Name = Name
     self.Amount = Amount
     return self
end

function Account:Deposit(Amount)
     self.Amount = self.Amount + Amount
end

function Account:Withdraw(Amount)
     if Amount > 0 and Amount <= self.Amount then
          self.Amount = self.Amount - Amount
     end
end

local myAccount = Account.new("name", 100)
myAccount:Deposit(50)
print(myAccount.Amount) --150

Make sure to read the link I posted to fully understand the code

3 Likes