I wanted to learn datastores and stuff like that,but for some reason when i rejoin the value of the second stat becomes the value of the first stat
Heres the script
local ServerStorageRemote = game:GetService("ServerStorage").RemoteData
local DataService = game:GetService("DataStoreService")
local StatsData = DataService:GetDataStore("Statistics")
game.Players.PlayerAdded:Connect(function(player)
local Lemon = player:WaitForChild("leaderstats").Lemon
local Yes = player:WaitForChild("leaderstats").Yes
local playerUID = "Player_" .. player.UserId
local data = {}
-- Load data
local success, errormessage = pcall(function()
data = StatsData:GetAsync(playerUID)
end)
-- Set data equal to the current stuff
if success then
Lemon.Value = data
Yes.Value = data
print("Succeeded at loading stuff")
end
if errormessage then
warn(errormessage)
end
end)
game.Players.PlayerRemoving:Connect(function(player)
-- Save
local Lemon = player:WaitForChild("leaderstats").Lemon
local Yes = player:WaitForChild("leaderstats").Yes
local playerUID = "Player_" .. player.UserId
local Saved = {
Lemon.Value,
Yes.Value,
}
local didit, errormessage = pcall(function()
StatsData:SetAsync(playerUID,Lemon.Value)
end)
if didit then
print("Succeeded at saving stuff")
elseif errormessage then
warn(errormessage)
end
end)
Before rejoining:
After rejoining:
How can i fix that?