Hello, I’m having issues atm, for some reason people that play my game would lose their data randomly and I have no clue why its happening. It would save some people’s data then some rare individuals would lose their data randomly. Can anyone please help?
The script
local DS = game:GetService(“DataStoreService”):GetDataStore(“PlayerData”)
game.Players.PlayerAdded:Connect(function(Player)
wait()
local PLRKEY = "id"..Player.userId
local DataFolder = Instance.new("Folder")
DataFolder.Name = "PlayerData"
DataFolder.Parent = Player
local CurrentLevel = Instance.new("IntValue")
CurrentLevel.Name = "CurrentLevel"
CurrentLevel.Parent = DataFolder
local CurrentDifficulty = Instance.new("IntValue")
CurrentDifficulty.Name = "CurrentDifficulty"
CurrentDifficulty.Parent = DataFolder
local Level1Difficulty = Instance.new("IntValue")
Level1Difficulty.Name = "Level1Difficulty"
Level1Difficulty.Parent = DataFolder
local Level2Difficulty = Instance.new("IntValue")
Level2Difficulty.Name = "Level2Difficulty"
Level2Difficulty.Parent = DataFolder
local Level3Difficulty = Instance.new("IntValue")
Level3Difficulty.Name = "Level3Difficulty"
Level3Difficulty.Parent = DataFolder
local Level4Difficulty = Instance.new("IntValue")
Level4Difficulty.Name = "Level4Difficulty"
Level4Difficulty.Parent = DataFolder
local Level5Difficulty = Instance.new("IntValue")
Level5Difficulty.Name = "Level5Difficulty"
Level5Difficulty.Parent = DataFolder
local Level6Difficulty = Instance.new("IntValue")
Level6Difficulty.Name = "Level6Difficulty"
Level6Difficulty.Parent = DataFolder
local Level7Difficulty = Instance.new("IntValue")
Level7Difficulty.Name = "Level7Difficulty"
Level7Difficulty.Parent = DataFolder
local Level8Difficulty = Instance.new("IntValue")
Level8Difficulty.Name = "Level8Difficulty"
Level8Difficulty.Parent = DataFolder
local Level1Highscore = Instance.new("IntValue")
Level1Highscore.Name = "Level1Highscore"
Level1Highscore.Parent = DataFolder
local Level2Highscore = Instance.new("IntValue")
Level2Highscore.Name = "Level2Highscore"
Level2Highscore.Parent = DataFolder
local Level3Highscore = Instance.new("IntValue")
Level3Highscore.Name = "Level3Highscore"
Level3Highscore.Parent = DataFolder
local Level4Highscore = Instance.new("IntValue")
Level4Highscore.Name = "Level4Highscore"
Level4Highscore.Parent = DataFolder
local Level5Highscore = Instance.new("IntValue")
Level5Highscore.Name = "Level5Highscore"
Level5Highscore.Parent = DataFolder
local Level6Highscore = Instance.new("IntValue")
Level6Highscore.Name = "Level6Highscore"
Level6Highscore.Parent = DataFolder
local Level7Highscore = Instance.new("IntValue")
Level7Highscore.Name = "Level7Highscore"
Level7Highscore.Parent = DataFolder
local Level8Highscore = Instance.new("IntValue")
Level8Highscore.Name = "Level8Highscore"
Level8Highscore.Parent = DataFolder
local Highscore = Instance.new("IntValue")
Highscore.Name = "Highscore"
Highscore.Parent = DataFolder
local Chaos = Instance.new("IntValue")
Chaos.Name = "Chaos"
Chaos.Parent = DataFolder
local Donation = Instance.new("IntValue")
Donation.Name = "Donation"
Donation.Parent = DataFolder
-- NONE SAVED
local Score = Instance.new("IntValue")
Score.Name = "Score"
Score.Parent = DataFolder
wait(0.001)
local SAVE1 = Player.PlayerData.CurrentLevel
local SAVE2 = Player.PlayerData.CurrentDifficulty
local SAVE3 = Player.PlayerData.Level1Difficulty
local SAVE4 = Player.PlayerData.Level2Difficulty
local SAVE5 = Player.PlayerData.Level3Difficulty
local SAVE6 = Player.PlayerData.Level4Difficulty
local SAVE7 = Player.PlayerData.Level5Difficulty
local SAVE8 = Player.PlayerData.Level6Difficulty
local SAVE9 = Player.PlayerData.Level7Difficulty
local SAVE10 = Player.PlayerData.Level8Difficulty
local SAVE11 = Player.PlayerData.Highscore
local SAVE12 = Player.PlayerData.Chaos
local SAVE13 = Player.PlayerData.Level1Highscore
local SAVE14 = Player.PlayerData.Level2Highscore
local SAVE15 = Player.PlayerData.Level3Highscore
local SAVE16 = Player.PlayerData.Level4Highscore
local SAVE17 = Player.PlayerData.Level5Highscore
local SAVE18 = Player.PlayerData.Level6Highscore
local SAVE19 = Player.PlayerData.Level7Highscore
local SAVE20 = Player.PlayerData.Level8Highscore
local SAVE21 = Player.PlayerData.Donation
local GetSaved = DS:GetAsync(PLRKEY)
if GetSaved then
SAVE1.Value = GetSaved[1]
SAVE2.Value = GetSaved[2]
SAVE3.Value = GetSaved[3]
SAVE4.Value = GetSaved[4]
SAVE5.Value = GetSaved[5]
SAVE6.Value = GetSaved[6]
SAVE7.Value = GetSaved[7]
SAVE8.Value = GetSaved[8]
SAVE9.Value = GetSaved[9]
SAVE10.Value = GetSaved[10]
SAVE11.Value = GetSaved[11]
SAVE12.Value = GetSaved[12]
SAVE13.Value = GetSaved[13]
SAVE14.Value = GetSaved[14]
SAVE15.Value = GetSaved[15]
SAVE16.Value = GetSaved[16]
SAVE17.Value = GetSaved[17]
SAVE18.Value = GetSaved[18]
SAVE19.Value = GetSaved[19]
SAVE20.Value = GetSaved[20]
SAVE21.Value = GetSaved[21]
else
local NumbersForSaving = {SAVE1.Value, SAVE2.Value, SAVE3.Value, SAVE4.Value,
SAVE5.Value, SAVE6.Value, SAVE7.Value, SAVE8.Value, SAVE9.Value, SAVE10.Value,
SAVE11.Value, SAVE12.Value, SAVE13.Value, SAVE14.Value, SAVE15.Value, SAVE16.Value,
SAVE17.Value, SAVE18.Value, SAVE19.Value, SAVE20.Value, SAVE21.Value}
DS:GetAsync(PLRKEY, NumbersForSaving)
end
CurrentDifficulty.Value = 1
repeat wait() until Player.Character
wait(1)
if Chaos.Value >= 1 then
wait(12)
Chaos.Value = 0
end
end)
game.Players.PlayerRemoving:Connect(function(Player)
local SAVE1 = Player.PlayerData.CurrentLevel
local SAVE2 = Player.PlayerData.CurrentDifficulty
local SAVE3 = Player.PlayerData.Level1Difficulty
local SAVE4 = Player.PlayerData.Level2Difficulty
local SAVE5 = Player.PlayerData.Level3Difficulty
local SAVE6 = Player.PlayerData.Level4Difficulty
local SAVE7 = Player.PlayerData.Level5Difficulty
local SAVE8 = Player.PlayerData.Level6Difficulty
local SAVE9 = Player.PlayerData.Level7Difficulty
local SAVE10 = Player.PlayerData.Level8Difficulty
local SAVE11 = Player.PlayerData.Highscore
local SAVE12 = Player.PlayerData.Chaos
local SAVE13 = Player.PlayerData.Level1Highscore
local SAVE14 = Player.PlayerData.Level2Highscore
local SAVE15 = Player.PlayerData.Level3Highscore
local SAVE16 = Player.PlayerData.Level4Highscore
local SAVE17 = Player.PlayerData.Level5Highscore
local SAVE18 = Player.PlayerData.Level6Highscore
local SAVE19 = Player.PlayerData.Level7Highscore
local SAVE20 = Player.PlayerData.Level8Highscore
local SAVE21 = Player.PlayerData.Donation
DS:SetAsync("id"..Player.userId, {SAVE1.Value, SAVE2.Value, SAVE3.Value, SAVE4.Value,
SAVE5.Value, SAVE6.Value, SAVE7.Value, SAVE8.Value, SAVE9.Value, SAVE10.Value,
SAVE11.Value, SAVE12.Value, SAVE13.Value, SAVE14.Value, SAVE15.Value, SAVE16.Value,
SAVE17.Value, SAVE18.Value, SAVE19.Value, SAVE20.Value, SAVE21.Value})
end)
local ChangeDifficultyR = game.ReplicatedStorage.RemoteData.LevelRemotes.ChangeDifficulty
ChangeDifficultyR.OnServerEvent:Connect(function(Player, Difficulty)
local PlayerData = Player:FindFirstChild(“PlayerData”)
local CurrentDifficulty = PlayerData:FindFirstChild("CurrentDifficulty")
CurrentDifficulty.Value = Difficulty
end)