Why is it only saving keys or meat and not both values?
local DataStoreService = game:GetService("DataStoreService")
local playerData = DataStoreService:GetDataStore("LeaderStatSave")
game.Players.PlayerAdded:Connect(function(player)
local leaderstats = Instance.new("Folder")
leaderstats.Name = "leaderstats"
leaderstats.Parent = player
local keys = Instance.new("IntValue")
keys.Name = "Keys"
keys.Parent = leaderstats
local Meat = Instance.new("IntValue")
Meat.Name = "Meat"
Meat.Parent = leaderstats
local data
local success, errormessage = pcall(function()
data = playerData:GetAsync(player.UserId.."-Keys")
end)
local data2
local success, errormessage = pcall(function()
data2 = playerData:GetAsync(player.UserId.."-Meat")
end)
if success then
keys.Value = data
Meat.Value = data2
else
print("Error while getting your data")
warn(errormessage)
end
end)
game.Players.PlayerRemoving:Connect(function(player)
local success, errormessage = pcall(function()
playerData:SetAsync(player.UserId.."-Keys", player.leaderstats.Keys.Value)
playerData:SetAsync(player.UserId.."-Meat", player.leaderstats.Meat.Value)
end)
if success then
print("Data successfully saved!")
else
print("There was an error while saving the data")
warn(errormessage)
end
end)