So, I'm playing around with data stores and attempting to change a playerAs data store values based on another playerBs actions.. Sadly, I apparently can't get playerAs data to update.. it always returns nil..
function DataStore:UpdateStatus(player, isOnline) output("Update") if not DataStore.isPlayerLoaded(player) then repeat wait() output("Waiting for Player:", player) until DataStore.isPlayerLoaded(player) else output("Player is loaded.", player) output("DataSize:", #sessionData[player]) end for i = 1, #sessionData[player] do local friendID = game.Players:GetUserIdFromNameAsync(sessionData[player][i]["Name"]) output("DEBUG", friendID) if friendID ~= nil then output(player, ":", sessionData[player][i]["Name"], "::", friendID) end local playerData = FriendData:GetAsync(friendID) output("DEBUG", playerData) if playerData ~= nil then for i, v in pairs(playerData) do output("DEBUG", i, v) end FriendData:SetAsync(game.Players:GetUserIdFromNameAsync(sessionData[player][i]["Name"], playerData)) end end end
Output
[MOD_SERVER_FRIENDS] DEBUG 26517 [MOD_SERVER_FRIENDS] Player1 : Player2 :: 26517 [MOD_SERVER_FRIENDS] DEBUG nil
I believe it is returning nil
because there is no existing key/save for that player. Add a conditional
(if) statement that checks if a save does not exist. If the save doesn't exist, then create one for the player.