SaveData = function(plr) local lstats = plr:FindFirstChild("leaderstats") if lstats~=nil then local Level = lstats:FindFirstChild("Level") local EXP = plr:FindFirstChild("EXP") local Coins = lstats:FindFirstChild("Coins") if Level~=nil and EXP~=nil and Coins~=nil then local tablestats = { Level.Value, EXP.Value, Coins.Value } local GetData = PlayerStats:GetAsync(plr.UserId) if GetData then PlayerStats:UpdateAsync(plr.UserId, function() return tablestats end) else PlayerStats:SetAsync(plr.UserId,tablestats) end end end end LoadData = function(plr,Level,EXP,Coins) local GetData = PlayerStats:GetAsync(plr.UserId) if GetData then Level.Value = GetData[1] EXP.Value = GetData[2] Coins.Value = GetData[3] else Level.Value = 1 EXP.Value = 0 Coins.Value = 0 end end
This is my current script for saving stats of players (Levels, EXP and Coins) it works perfectly fine so far and I'm happy with it, but I know and have been told datastore errors occur and I should prepare for them. How would I make these datastore functions be able to handle errors that may occur so I could possibly kick the player if their data could be removed or not saved?