Hello, Developers.
So I have a DataStore system that uses a pcall and SetAsync to retrieve Data. For some reason, sometimes when the player joins the game, their data is all 0, or doesn’t load properly (like some of it loads and some of it doesn’t). Sometimes it fixes itself if you rejoin, but sometimes it doesn’t. There’s no errors in the output or anything. Here is my code:
module.LoadData = function(player, PlayerFolder)
local success, result, err = pcall(PlayerData.GetAsync, PlayerData, player.UserId)
if not success then
warn(err)
game:GetService("ReplicatedStorage").RemoteEvents.WarnDatastore:FireClient(player, err)
table.insert(DataErrors, player.Name)
return
end
if result then
PlayerFolder.DataId.Value = result.DataId
PlayerFolder.Credits.Value = result.Credits
PlayerFolder.Wins.Value = result.Wins
PlayerFolder.Level.Value = result.Level
PlayerFolder.Experience.Value = result.Exp
for i,v in pairs(result.Codes) do
local t = Instance.new("BoolValue")
t.Name = v
t.Parent = PlayerFolder.Codes
end
for i,v in pairs(result.Backpack) do
local t = Instance.new("BoolValue")
t.Name = v
t.Parent = PlayerFolder.Backpack
end
else
PlayerFolder.Credits.Value = 0
PlayerFolder.Wins.Value = 0
PlayerFolder.DataId.Value = 0
PlayerFolder.Level.Value = 1
end
end