I am trying to develop a game in Roblox and I have am cannot call a method on a class that I created. I have added my steps below. I am certain the path to the model is correct and I think I have created everything as I should.
I have created the following model
local PlayerLeagueUpdateModel = { }
PlayerLeagueUpdateModel.__index = PlayerLeagueUpdateModel
function PlayerLeagueUpdateModel.new(playerKey: StringValue)
local self = setmetatable({ }, PlayerLeagueUpdateModel)
self.PlayerKey = playerKey
return self
end
function PlayerLeagueUpdateModel:GetPlayerKey()
return self.PlayerKey
end
return PlayerLeagueUpdateModel
In a separate file I create a new instance of this model and I call GetPlayerKey(). Then print the result. It prints the expected value. I have provided the code below. I then fire a bindable event.
local playerLeagueUpdateModel = PlayerLeagueUpdateModel.new(playerKey)
local playerKey = playerLeagueUpdateModel:GetPlayerKey()
print(playerKey)
PlayerBindableEvent:Fire(saveEventType, player, playerLeagueUpdateModel)
I have a script watching for this bindable event. The script is provided below
local function HandlePlayerActiveInLeagueUpdate(eventType: EventTypes, player: Player, playerLeagueUpdateModel: PlayerLeagueUpdateModel)
local playerKey = playerLeagueUpdateModel:GetPlayerKey()
print(playerKey)
PlayerDataManager.UpdatePlayerLeagueData(player, playerLeagueUpdateModel)
end
When I call playerLeagueUpdateModel:GetPlayerKey() I get the following error message
attempt to call missing method 'GetPlayerKey' of table
What am I doing wrong?