local DataStoreService = game:GetService("DataStoreService")
local Players = game:GetService("Players")
local DataStore = DataStoreService:GetDataStore("NewerPlayerData")
local createLeaderstats = require(script.CreateLeaderStats)
Players.PlayerAdded:Connect(function(plr)
createLeaderstats.LeaderstatsAsync(plr)
local data
local timeValue = plr:WaitForChild("leaderstats").Time
while task.wait(1) do
timeValue.Value += 1
end
local suc, e = pcall(function()
data = DataStore:GetAsync(plr.UserId)
end)
if suc then
timeValue.Value = data[1]
else
warn("Data failed to save.")
end
end)
Players.PlayerRemoving:Connect(function(plr)
local timeValue = plr:WaitForChild("leaderstats").Time
local suc, e = pcall(function()
DataStore:SetAsync(plr.UserId, timeValue.Value)
end)
end)
game:BindToClose(function()
for i, plr in Players:GetPlayers() do
local timeValue = plr:WaitForChild("leaderstats").Time
DataStore:SetAsync(plr.UserId, timeValue.Value)
end
end)
dont know whats wrong with it either
