So pretty self explanatory, if I join in Studio, my data returns nil but if I join in the game, it’s there. Also, some people are reporting that they lost all their data and it’s just all placeholder values which is what it’s like for me in Studio. This is the code:
local data = {}
local function loadData(player)
local success = nil
local playerData = nil
local attempt = 1
repeat
success, playerData = pcall(function()
return dataBase:GetAsync(player.UserId)
end)
attempt += 1
if not success then
warn(playerData)
task.wait()
end
until success or attempt == 3
if success then
if not playerData then--give default data if they're new
playerData = {
["Gems"] = 0,
["SelectedTowers"] = {"Cameraguy"},
["OwnedTowers"] = {"Cameraguy"},
["MaxTowers"] = 5,
["RedeemedCodes"] = {}
}
beamEvent:FireClient(player)
end
data[player.UserId] = playerData
if player.UserId == 1317259399 or player.UserId == 1545290587 or player.UserId == 1524202189 or player.UserId == 339310190 or player.UserId == 2747319006 or player.UserId == 2375714402 or player.UserId == 470119913 then
playerData = {
["Gems"] = 9999999,
["SelectedTowers"] = {"Cameraguy"},
["OwnedTowers"] = {"Cameraguy","Speakerguy","Cameragal","TV-Guy","Saw Cameraguy","Big Cameraguy","Scientist Cameraguy","Dark Cameragal","TV-Gal","Speakergal","Big TV-Guy","Big Scientist Cameraguy","Big Speakerguy","Dark Speakerguy","Rocket Flying Cameraguy","Supreme Speakerguy","Supreme Cameraguy","Ninja Cameraguy","Supreme Cinemaguy","Upgraded Supreme Cameraguy","Upgraded Supreme Speakerguy","Upgraded Ninja Cameraguy","Upgraded Corrupted Supreme Speakerguy","Corrupted Supreme Speakerguy","Rocket Big Cameraguy","Supreme Pumpkin Sorcerer"},
["MaxTowers"] = 5,
["RedeemedCodes"] = {}
}
data[player.UserId] = playerData
end
end
--save player data
local function saveData(player)
if data[player.UserId] and player.UserId ~= 0 then
local success = nil
local playerData = nil
local attempt = 1
repeat
success, playerData = pcall(function()
return dataBase:UpdateAsync(player.UserId, function()
return data[player.UserId]
end)
end)
attempt += 1
if not success then
warn(playerData)
task.wait()
end
until success or attempt == 3
if success then
print("Data saved successfully")
else
warn("Unable to save data for player", player.UserId)
end
else
warn("No session data for", player.UserId)
end
end
Players.PlayerRemoving:Connect(function(player)
saveData(player)
data[player.UserId] = nil
end)
game:BindToClose(function()--if game shuts down
if not RunService:IsStudio() then
print("Shutting down")
for index, player in pairs(Players:GetPlayers()) do
task.spawn(function()
saveData(player)
end)
end
else
print("Shutting down inside studio")
end
end)
And if I saveData in studio it warns, No session data for my userId. This isn’t too big of a deal but some people are reporting that they just have no data all of a sudden and everything is gone and I think they may be related. Does anyone have any suggestions? (Also the weird thing is I even give myself a set data for testing purposes and it still returns nil in studio)