idk why but the datastore does not work when i go into the client and change it then return to the main client and then leave. When i rejoin nothing comes up as an error
local Folder = Instance.new("Folder")
Folder.Parent = Player
Folder.Name = "leaderstats"
local Wins = Instance.new("IntValue")
Wins.Parent = Folder
Wins.Name = "Wins"
Wins.Value = 0
local Coins = Instance.new("IntValue")
Coins.Parent = Folder
Coins.Name = "Coins"
Coins.Value = 0
local playerUserId = "Player_"..Player.UserId
local data
local success, errormessage = pcall(function()
data = DataStore:GetAsync(playerUserId)
end)
if success then
Wins.Value = data[1]
Coins.Value = data[2]
end
end)
game.Players.PlayerRemoving:Connect(function(player)
local playerUserId = "Player_"..player.UserId
local Wins = player.leaderstats.Wins
local Coins = player.leaderstats.Coins
local data = {Wins.Value, Coins.Value}
local success, errormessage = pcall(function()
DataStore:SetAsync(playerUserId, data)
end)
if success then
print("Data successfully saved!")
if data then
print("Data collected!")
-- data is a table
Wins.Value = data[1]
Coins.Value = data[2]
else
-- no data
--probably the players first time playing
end
else
print("There was an error!")
warn(errormessage)
end
end)```