i opened a previous thread about this script ive been messing with and for some reason the data will not save or store itself after a player leaves the game its frustrating me cuz i cant seem to figure out if its this script or another one interferring with it
--
game.Players.PlayerAdded:Connect(function(Player)
local Leaderstats = Instance.new("Folder")
Leaderstats.Name = "leaderstats"
Leaderstats.Parent = Player
local Minutes = Instance.new("IntValue")
Minutes.Name = "Time"
Minutes.Value = 0
Minutes.Parent = Leaderstats
local Data = TimeStore:GetAsync(Player.UserId)
if Data then
Minutes.Value = Data
end
coroutine.resume(coroutine.create(function()
while true do
wait(60)
Minutes.Value = Minutes.Value + 1
end
end))
end)
game.Players.PlayerRemoving:Connect(function(Player)
TimeStore:SetAsync(Player.UserId, Player.leaderstats.Minutes.Value)
end)
game:BindToClose(function()
for i, Player in pairs(game.Players:GetPlayers()) do
TimeStore:SetAsync(Player.UserId, Player.leaderstats.Minutes.Value)
end
end)
It says Player.leaderstats.Minutes.Value, shouldnt it be Player.leaderstats.Time.Value??? The leaderstat name is “Time” and that is what is being added to the players leaderstats so that is what you should be looking for.
--
--
local Players = game:GetService("Players")
Players.PlayerAdded:Connect(function(Player)
local Leaderstats = Instance.new("Folder")
Leaderstats.Name = "leaderstats"
Leaderstats.Parent = Player
local Minutes = Instance.new("IntValue")
Minutes.Name = "Time"
Minutes.Value = 0
Minutes.Parent = Leaderstats
local Data = TimeStore:GetAsync(Player.UserId)
if Data then
Minutes.Value = Data
end
coroutine.resume(coroutine.create(function()
while true do
task.wait(60)
Minutes.Value += 1
end
end))
end)
Players.PlayerRemoving:Connect(function(Player)
TimeStore:SetAsync(Player.UserId, Player.leaderstats.Time.Value)
end)
game:BindToClose(function()
for i, Player in pairs(Players:GetPlayers()) do
TimeStore:SetAsync(Player.UserId, Player.leaderstats.Time.Value)
end
end)
After every 60 seconds? I doubt it. The DataStoreService has been getting more and more optimized. Autosaving every 60 seconds is a bad practice in large servers.
This solution fixes the spelling mistake from the OP’s code, but the coroutine should also be preferably removed. What is it even for, anyways? The loop is at the end of the thread.