Code :
local datastore = game:GetService("DataStoreService"):GetDataStore("Time")
game.Players.PlayerAdded:Connect(function(player)
local s = Instance.new("Folder", player)
s.Name = "leaderstats"
local a = Instance.new("IntValue", s)
a.Name = "Age"
a.Value = player.AccountAge
local b = Instance.new("IntValue", s)
b.Name = "Time"
local c = Instance.new("StringValue",s)
c.Name = "FPS"
local timee
local s,e = pcall(function()
timee= datastore:GetAsync(player.UserId)
end)
if s then
b.Value = timee
end
game.Players.PlayerRemoving:Connect(function(plr)
local timeee = plr.leaderstats.Time.Value
local s,e = pcall(function()
datastore:SetAsync(plr.UserId,timeee)
end)
if s then
print("Time", timeee)
else
print("Error : ", e)
end
end)
end)
When I rejoin the time resets back to zero instead of what I had last time.

5 comments
Take player removing out of player added. make it its own function. (idk if dat dos anything but it no ned be inside that) also are you testing in studio or in game
Also, when you set or get data, doesn't it have to be tostring(player.UserId) instead of just player.UserId
yes when accesing a datastores value the key has to be a string instead of a number
This worked, consider leaving a answer so others can find out and so I can accept it.
I'd recommend using datastore2 btw. This can be used to prevent dataloss and is far more effective than the roblox datastore.