In my game I am using profile service. When ever I try to update the data it says nil but after it says it exitsts i will be marking where these print statments are so you can see
– here is the error
10:47:05.300 ▶ Starting Init (x2) - Server - PlayerDataHandler:52
10:47:06.391 {} - Server - PlayerDataHandler:55
10:47:06.392 {} - Server - PlayerDataHandler:68
10:47:06.392 nil - Server - PlayerDataHandler:69
10:47:06.392 ServerScriptService.PlayerDataHandler:70: missing argument #2 - Server - PlayerDataHandler:70
10:47:06.392 Stack Begin - Studio
10:47:06.392 Script 'ServerScriptService.PlayerDataHandler', Line 70 - function GetProfile - Studio - PlayerDataHandler:70
10:47:06.392 Script 'ServerScriptService.PlayerDataHandler', Line 94 - function Update - Studio - PlayerDataHandler:94
10:47:06.392 Script 'ServerScriptService.Script', Line 11 - Studio - Script:11
10:47:06.392 Stack End - Studio
10:47:06.524 [ProfileService]: Roblox API services available - data will be saved - Server - ProfileService:2307
10:47:08.313 ▶ {...} - Server - PlayerDataHandler:39
here is the data store script
local PlayerDataHandler = {}
local ProfileStore = require(script.Parent:FindFirstChild("BaseModules"):WaitForChild("ProfileService"))
local dataTemplate = require(script:WaitForChild("Attributes"))
local players = game:GetService("Players")
local profileStorage = ProfileStore.GetProfileStore(
"PlayerData",
dataTemplate
)
local Playerprofiles = {}
local function PlayersAdded(player)
local profile = profileStorage:LoadProfileAsync (tostring(player.UserId))
------------------------------------------------------------------------------------------
if profile then
profile:AddUserId(player.UserId) -- loads profile
profile:Reconcile()
-------------------------------------------------------------------------------------
profile:ListenToRelease(function()
Playerprofiles[player] = nil
player:Kick()
end)
-------------------------------------------------------------------------------------
if player:IsDescendantOf (players) then
Playerprofiles[player] = profile
print(Playerprofiles) --Shows profile
print(Playerprofiles[player]) -- prints the whole data system for profile
print(profile) -- prints just the profile
else
profile:Release()
end
--------------------------------------------------------------------------------------
else
player:Kick("Failed to load profile : Player Data")
end
end
function PlayerDataHandler:Init()
print("Starting Init")
for _ , player in ipairs(players:GetPlayers())do
coroutine.wrap(PlayersAdded, player)
print(Playerprofiles) --Empty Table
end
game.Players.PlayerAdded:Connect(PlayersAdded)
game.Players.PlayerRemoving:Connect(function(player)
if Playerprofiles[player] then
Playerprofiles[player]:Release()
end
end)
end
local function GetProfile (Player)
print(Playerprofiles) -- EMPTY TABLE
print(Playerprofiles[Player]) --SAYS NIL
assert(Playerprofiles[Player], string.format("Data does not exist for %s".. Player.UserId))
return Playerprofiles[Player]
end
--Get/Set Data
function PlayerDataHandler:Get (Player, data)
local profile = GetProfile(Player)
assert(profile.Data[data], string.format("Data does not exist for %s",data))
return profile.Data[data]
end
-------------------------------------------------------------
function PlayerDataHandler:Set (Player, data, value)
local profile = GetProfile(Player)
assert(profile.Data[data], string.format("Data does not exist for %s",data))
assert(type(profile.Data[data] == type(value)))
profile.Data[data] = value
end
function PlayerDataHandler:Update (Player, data, callBack)
local profile = GetProfile(Player)
local oldData = self:Get(Player, data)
local newData = callBack(oldData)
self:Set(Player, data, newData)
end
function PlayerDataHandler.UpdateInventory(player, data, item)
end
return PlayerDataHandler
here is the init script I use
local playerDataHandler = require(script.Parent.PlayerDataHandler)
local ProfileStore = require(script.Parent:FindFirstChild("BaseModules"):WaitForChild("ProfileService"))
local Attribute = require(script.Parent:WaitForChild("PlayerDataHandler"):FindFirstChild("Attributes"))
playerDataHandler:Init()
game.Players.PlayerAdded:Connect(function(plr)
playerDataHandler:Init()
playerDataHandler:Update(plr, "Inventory" , function(currentInventory)
table.insert(currentInventory, "Wooden_Sword")
end)
end)