Everything I have read pcall should be used with Datastore because Datastore tends to error, I just started creating my script, but not exactly sure how to incorporate pcall into my script. I haven't started the saving portion of the script because I am going to be adding and saving many variables.
local DataStore = game:GetService("DataStoreService") local dataPoints = DataStore:GetDataStore("testPoints") game.Players.PlayerAdded:connect(function(plr) local points = Instance.new("IntValue",plr) points.Name = "Points" points.Value = dataPoints:GetAsync(plr.userId) or 0 end)
You can just surround the areas that you are loading and saving data with a pcall. The way you can do this is thus:
local success, message = pcall(function() --[[ what I am doing here is giving two names(they can be anything you want) to the two values that pcall will return. the first one success will return a Boolean value if the code inside of the pcall runs successfully(which is why the name is used) then it will return true if not it will return false. The second one message is a string which is the error message if the code fails. Otherwise it will return nil. ]]-- -- just put your code in here end)
You can use the variables to notify the player if you want to tell them that their data saved or failed to save. Or you can just print it to the output. It is all up to you. That is why it is so useful. Hope this helps and have a great day scripting!