Hello, can someone tell me where’s the problem in this script? My data saves if I only save one data but if I save two it doesn’t.
local DataStoreService = game:GetService("DataStoreService")
local myPlayerDataStore = DataStoreService:GetOrderedDataStore("myPlayerDataStore")
game.Players.PlayerAdded:Connect(function(player)
local leaderstats = Instance.new("Folder")
leaderstats.Parent = player
leaderstats.Name = "leaderstats"
local deaths = Instance.new("IntValue")
deaths.Parent = leaderstats
deaths.Name = "Deaths"
local completions = Instance.new("IntValue")
completions.Parent = leaderstats
completions.Name = "Completion"
local playerUserId = "Player_"..player.UserId
local success, errormessage = pcall(function()
deathsData = myPlayerDataStore:GetAsync(playerUserId)
completionsData = myPlayerDataStore:GetAsync(playerUserId)
end)
if success then
deaths.Value = deathsData
completions.Value = completionsData
end
end)
game.Players.PlayerRemoving:Connect(function(player)
local playerUserId = "Player_"..player.UserId
local deathsData = player.leaderstats.Deaths.Value
local completionsData = player.leaderstats.Completion.Value
local saveDataTable = {deathsData, completionsData}
for i , v in pairs (saveDataTable) do
myPlayerDataStore:SetAsync(playerUserId, v)
end
end)