Hello. I am trying to make a new leaderstat that goes up every second you play and I am unable to save it. I have read over the script multiple times, followed various tutorials, but nothing seems to work. Here is the script:
local data = game:GetService("DataStoreService")
local ds = data:GetDataStore("timeplayed")
game.Players.PlayerAdded:Connect(function(player)
local leaders = Instance.new("Folder")
leaders.Name = "leaderstats"
leaders.Parent = player
local secsingame = Instance.new("IntValue")
secsingame.Name = "PlayPoints"
secsingame.Parent = leaders
while wait(1) do
player.leaderstats.Playtime.Value = player.leaderstats.PlayPoints.Value + 1
end
local data
local success, errormessage = pcall(function()
data = ds:GetAsync("playpoints"..player.UserId)
end)
if success then
secsingame.Value = data
end
end)
game.Players.PlayerRemoving:Connect(function(player)
local success, errormessage = pcall(function()
ds:SetAsync("playpoints"..player.UserId, player.leaderstats.PlayPoints.Value)
end)
end)
Thanks for any help!