would their data be overwritten?
first of all
datastore:GetAsync will probably fail when DataStore is down
you should wrap that around pcall and if it fails to get data kick the player
you should always save player data when they leave but never try to save data after player got kicked for datastore:GetAsync fail
all the leaderstats scripts I see they don’t do that even alvinblox doesn’t do that
I wrapped datastore:GetAsync in pcall in one of my test games
i joined when datastore was down and it actually kicked me for datastore being down
works? yes but you might lose some players when datastore is down but still better than player reporting data loss
That’s kind of confusing. If you wrap it into a pcall and kick the plr if it’s not a success then you’d also be kicking new players. Is there any way around this?
if its not a success then it shouldnt even return any data in first place and it should be error string instead of data
Success would tell whether or not you successfully found the data store… so I’m confused bcz if you do if success then give plr the data else kick player end… you’d be kicking new players along with any plr who failed to get data…? Right?
No, it doesnt work like that you don’t understand what im trying to say.
edit: you might also want to wrap GetDataStore into pcall because that might error too when roblox datastore is down (in that case retry or kick everyone from the server because the game can’t load player data correctly)
local data=game:GetService("DataStoreService"):GetDataStore("test")
game:GetService("Players").PlayerAdded:Connect(function(player)
local success,player_data=pcall(function()
return data:GetAsync(tostring(player.UserId))
end)
if success and player_data == nil then
print("new player no data")
end
if success and player_data then
print("old player and the player got data")
end
if success==false then --failed and error message is player_data
print(typeof(player_data),player_data) --string, error message
end
end)
Keep in mind this is “scripting support” not “boost my ego with knowing more than people new to Roblox studio” … I was just confused. There’s nothing wrong with asking questions, especially on a forum category made for asking questions. Thanks for showing me. I guess?
my bad for not providing examples next time i’ll do that
Add that case to your retry logic. Basically try to fetch their data a few times with increasing intervals and don’t allow any setting of values or saving during the fetching time(even if they leave). If you notice that the errors you get are internal server errors(not rate limits) and they pass some limit(for example more than 10 internal server errors with increasing intervals in the row for the same player) then kick the player with the message that “Roblox datastores may be down and your data hasn’t been impacted”. If the data loads in successfully then set a value(it can be any value, module value, BoolValue, etc) of “DataLoaded” for the associated player to true. Only allow scripts to overwrite data and save data to datastores if the data has loaded according to the value of DataLoaded. This allows you to discriminate between players who failed to load and new ones.
guys I ended up creating a boolvalue inside the player and if the player doesnt load properly then it gets set to false and when the player leaves it checks for that boolvalue and if its false it doesn’t save their unloaded data