So this latest outage wiped the data of most of our players on our DataStore, and very few have had their data stay intact.
How can we keep this from happening again? I’m not well versed in DataStores.
Here’s our DataStore’s script:
local DataStoreService = game:GetService("DataStoreService")
local myDataStore = DataStoreService:GetDataStore("TimeData")
local BadgeService = game:GetService("BadgeService")
game.Players.PlayerAdded:Connect(function(player)
local leaderstats = Instance.new("Folder")
leaderstats.Name = "leaderstats"
leaderstats.Parent = player
local Time = Instance.new("IntValue")
Time.Name = "Minutes"
Time.Parent = leaderstats
local playerUserId = "Player"..player.UserId
local data
local success, errormessage = pcall(function()
data = myDataStore:GetAsync(playerUserId)
end)
if success then
Time.Value = data --loads data when player joins
end
while wait(60) do
player.leaderstats.Minutes.Value = player.leaderstats.Minutes.Value + 1 --makes time go up by one every minute
end
end)
game.Players.PlayerRemoving:Connect(function(player)
local playerUserId = "Player"..player.UserId
local data = player.leaderstats.Minutes.Value
myDataStore:SetAsync(playerUserId, data) --saves data when player leaves game
print(player.Name,"left the game. They have",data,"minutes.")
end)
I’m also worried the same has occurred with my other game that utilizes DataStores. Here’s its script:
local stat = "Points"
local startamount = 0
local DataStore = game:GetService("DataStoreService")
local ds = DataStore:GetDataStore("LeaderStatSave")
game.Players.PlayerAdded:connect(function(player)
print("welcome", player.Name, "! heres your points.")
local leader = Instance.new("Folder",player)
leader.Name = "leaderstats"
local Cash = Instance.new("IntValue",leader)
Cash.Name = stat
local cpoints = Instance.new("IntValue",leader)
cpoints.Name = "Current Points"
cpoints.Value = 0
Cash.Value = ds:GetAsync(player.UserId) or startamount
ds:SetAsync(player.UserId, Cash.Value)
Cash.Changed:connect(function()
if player.leaderstats.Points.Value <= -1 then
print(player.Name, "triggered an overflow. returning to max points...")
player.leaderstats.Points.Value = 9223372036854780000
ds:SetAsync(player.UserId, player.leaderstats.Points.Value)
wait(60) --stop spamming the datastore!!!
end
end)
end)
game.Players.PlayerRemoving:connect(function(player)
print(player.Name, "left. saving points... they have", player.leaderstats.Points.Value, "points.")
ds:SetAsync(player.UserId, player.leaderstats.Points.Value) --Change "Points" to the name of your leaderstat.
local success, err = pcall(function()
return ds:SetAsync(player.UserId, player.leaderstats.Points.Value)
end)
if success then
print("point save successful")
else
warn("point save failed!")
end
end)
Please provide code samples in your responses if you can, I learn best from example!