I decided to try tackling OOP, and I set up an interactive example following the advice given by tutorials on the devforum. However when I try calling a function within the ‘newPhone’ object, it keeps on saying it is nil, even though the function exists. What am I doing wrong? Server Script
local phoneOOP = require(game.ServerStorage.phoneOOP)
local newPhone = phoneOOP.New("RandomPhone", "RandomModel", 70)
setmetatable(newPhone, phoneOOP)
newPhone:Charge() --Erroring Here
print(newPhone.Battery)
Module
local phoneTable = {}
phoneTable._index = phoneTable
function phoneTable.New(Brand, Model, Battery)
local newPhone = {}
setmetatable(newPhone, phoneTable)
newPhone.Brand = Brand
newPhone.Model = Model
newPhone.Battery = Battery
return newPhone
end
function phoneTable:Charge()
self.Battery += 10
end
return phoneTable