Hi everyone, I am abit new to type checking and I am stuck on this weird error while creating a Profile class by using the ProfileStore module.
This is my code.. apparently when I try to insert a number into the table, I am met with that error (In the title).
function ProfileController.Get(self : ProfileController, Player : Player) : Profile.Profile?
table.insert(self.Profiles[Player].Session.Data.Passes, 3)
return self.Profiles[Player]
end
-- Error highlights on table.insert.
-- Another snippet
function ProfileController.Register(self : ProfileController, Player : Player) : Profile.Profile
self.Profiles[Player] = Profile.new(Player) :: Profile.Profile
return self.Profiles[Player]
end
Snippet of ProfileClass:
local Profile = {}
Profile.__index = Profile
Profile.Template = {
Passes = {} :: {number},
PsuedoPasses = {} :: {number},
}
Profile.PlayerStore = ProfileStore.New("DataStore", Profile.Template)
export type Template = typeof(Profile.Template)
export type Session = ProfileStore.Profile<Template>
export type Profile = typeof(setmetatable({} :: {Player : Player, Session : Session}, Profile))
function Profile.new(Player : Player, Reconcile : boolean?) : Profile?
local self = setmetatable({Player = Player}, Profile) :: Profile
self.Session = Profile.PlayerStore:StartSessionAsync(`{Player.UserId}`, {
Cancel = function()
return not Player:IsDescendantOf(Players)
end,
}) :: Session
if not self.Session or not Player:IsDescendantOf(Players) then
self:Destroy()
self.Player:Kick("Profile couldn't load - Please Rejoin.")
return nil
end
Reconcile = Reconcile or true --> Default Value.
if Reconcile then
self.Session:Reconcile()
end
return self
end