Alright, so I have a module script which contains a bunch of methods for storing, changing, and getting player data. There is a table called sessionData which stores players. Attached to each player is a set of identical data(values may be different, but there is the same number of keys and all key names are the same). The problem arises when I try call setAsync in the module script.
sessionData var
local sessionData = {}
This data table is copied to each player if getAsync returns nil(meaning this player doesn't have an existing data set
data = {Coins = 0, Gold = 0, Level = 1, cpCurrent = 0,
cpMax = 0, cpPerLvl = 0, cpRecovery = 0, expCurrent = 0,
expNeeded = 0, hpMax = 75, hpPerLvl = 0.15}
After creating a data set for new players, it sets the data to an index in sessionData which can be referenced by the player
sessionData[player] = data
Tries to call this method but returns an error, both after setting a new data set and for saving data which are the two times in the module script that setAsync() is called
playerData:SetAsync(player.UserId, sessionData[player])
Note: These methods are called in another script using PlayerAdded and PlayerRemoving and the player object passed from both these events is passed on to the function via parameter.
This is the error
13:00:10.748 - Argument 2 missing or nil
13:00:10.751 - Script 'ServerStorage.PlayerStatManager', Line 27 - method savePlayerData
13:00:10.753 - Script 'Workspace.setup', Line 8
13:00:10.755 - Stack End
PlayerAdded and PlayerRemoving regular script located in workspace
local module = require(game.ServerStorage.PlayerStatManager)
game.Players.PlayerAdded:connect(function(player)
module:setupPlayerData(player) --SetAsync() in this method returns error
end)
game.Players.PlayerRemoving:connect(function(player)
module:savePlayerData(player) --SetAsync() in this method returns an error
end)

2 comments
Are you using DataStore or Data Persistence?
DataStore