I was adding settings to my DataStore script, when all of a sudden, it erased all my data and doesn’t save anything. There were no errors or warnings.
This is my script
local Players = game:GetService('Players')
local DataStoreService = game:GetService("DataStoreService")
local myDataStore = DataStoreService:GetDataStore("myDataStore")
local function OnPlayerAdded(player)
local leaderstats = Instance.new("Folder", player)
leaderstats.Name = "leaderstats"
local nonleaderstats = Instance.new("Folder", player)
nonleaderstats.Name = "nonleaderstats"
local rank = Instance.new("StringValue", leaderstats)
rank.Name = "Rank"
rank.Value = player:GetRoleInGroup(16597728)
local Coins = Instance.new("IntValue", nonleaderstats)
Coins.Name = "Coins"
local Points = Instance.new("IntValue", nonleaderstats)
Points.Name = "Points"
local PromoPoints = Instance.new("IntValue", nonleaderstats)
PromoPoints.Name = "PromoPoints"
local multi = Instance.new("IntValue", nonleaderstats)
multi.Name = "Multiplier"
local QuickLoad=Instance.new("IntValue",nonleaderstats)
QuickLoad.Name="quickload"
local data = myDataStore:GetAsync("Player_"..player.UserId)
if data then
print("Player data loaded successfully!")
Coins.Value = data.Coins or 0
Points.Value = data.Points or 0
PromoPoints.Value = data.PromoPoints or 0
QuickLoad.Value=data.QuickLoad or 0
else
print("No player data found for "..player.Name)
end
end
local function CreateTable(player)
local PlayerData = {}
for _, value in ipairs(player.nonleaderstats:GetChildren()) do
PlayerData[value.Name] = value.Value
end
return PlayerData
end
local function OnPlayerRemoving(player)
local success, errormessage = pcall(function()
myDataStore:SetAsync("Player_"..player.UserId, CreateTable(player))
end)
if success then
print("Player data was successfully saved for "..player.Name)
else
print("Error saving data for "..player.Name..": "..errormessage)
end
end
Players.PlayerAdded:Connect(OnPlayerAdded)
Players.PlayerRemoving:Connect(OnPlayerRemoving)
game:BindToClose(function()
for _, player in ipairs(Players:GetPlayers()) do
OnPlayerRemoving(player)
end
end)