local DataStoreService = game:GetService("DataStoreService")
local Event = game:GetService("ReplicatedStorage"):WaitForChild("Events"):WaitForChild("SaveMyStats")
game.Players.PlayerAdded:Connect(function(player)
local Stats = Instance.new("Configuration", player)
Stats.Name = "Stats"
-- Main stats
local diamonds = Instance.new("IntValue", Stats)
diamonds.Name = "Diamonds"
diamonds.Value = DataStoreService:GetDataStore("DiamondDataStore"):GetAsync(player.UserId) or 0
local level = Instance.new("IntValue", Stats)
level.Name = "Level"
level.Value = DataStoreService:GetDataStore("LevelDataStore"):GetAsync(player.UserId) or 1
--
-- Other stats
local parachute = Instance.new("StringValue", Stats)
parachute.Name = "Parachute"
parachute.Value = DataStoreService:GetDataStore("ParachuteDataStore"):GetAsync(player.UserId) or "Black"
local skydiveseconds = Instance.new("IntValue", Stats)
skydiveseconds.Name = "SkydiveSeconds"
skydiveseconds.Value = DataStoreService:GetDataStore("SkydiveSecondsDataStore"):GetAsync(player.UserId) or 0
local tutorial = Instance.new("BoolValue", Stats)
tutorial.Name = "Tutorial"
tutorial.Value = DataStoreService:GetDataStore("TutorialDataStore"):GetAsync(player.UserId) or false
--
end)
function SaveMyStats(player)
-- Main stats
if player:FindFirstChild("Stats") then
DataStoreService:GetDataStore("DiamondDataStore"):SetAsync(player.UserId, player.Stats:FindFirstChild("Diamonds").Value)
local level = DataStoreService:GetDataStore("LevelDataStore"):GetAsync(player.UserId)
if level ~= nil and level <= player.Stats:FindFirstChild("Level").Value then
DataStoreService:GetDataStore("LevelDataStore"):SetAsync(player.UserId, player.Stats:FindFirstChild("Level").Value)
elseif level == nil then
DataStoreService:GetDataStore("LevelDataStore"):SetAsync(player.UserId, player.Stats:FindFirstChild("Level").Value)
end
--
-- Other stats
DataStoreService:GetDataStore("ParachuteDataStore"):SetAsync(player.UserId, player.Stats:FindFirstChild("Parachute").Value)
DataStoreService:GetDataStore("SkydiveSecondsDataStore"):SetAsync(player.UserId, player.Stats:FindFirstChild("SkydiveSeconds").Value)
DataStoreService:GetDataStore("TutorialDataStore"):SetAsync(player.UserId, player.Stats:FindFirstChild("Tutorial").Value)
--
end
end
game.Players.PlayerRemoving:Connect(SaveMyStats)
Event.OnServerEvent:Connect(SaveMyStats)
This is the script I use to store and load data in my games. It sometimes resets player data, which is really annoying. A friend of mine told me to use "pcall()"s, but I couldn’t implement it to the current script. Also, another friend of mine asked me why not put everything on one data store, I don’t know how to do that either.
If someone could help me rewrite this, that would be much appreciated!