I've been using a stat script in my game and it has been saving until one time when everyone started telling me that their stats didn't save. I don't know what the reason is. This is the script:
game.Players.PlayerAdded:Connect(function(plr)
local DS = game:GetService("DataStoreService")
local Stats = Instance.new("Folder", plr)
Stats.Name = "Stats"
for i,v in pairs(script:GetChildren()) do
local DSnew = DS:GetDataStore(v.name)
local newStat = Instance.new("NumberValue",Stats)
newStat.Name = v.Name
newStat.Value = DSnew:GetAsync(plr.userId.."-testdatastores") or v.value
end
end)
game. Players.PlayerRemoving:Connect(function(plr)
for i,v in pairs(script:GetChildren()) do
print("Accept!")
local DS = game:GetService("DataStoreService")
local DSnew = DS:GetDataStore(v.name)
DSnew:SetAsync(plr.UserId.."-testdatastores", plr.Stats[v.name].Value)
print("Saved!")
end
end)
It has a couple of NumberValues with the stat names but nothing happened when I added more, it just kind of started to break out of nowhere and I need help on understanding why this happened and how can I possibly fix this issue.

1 comment
thanks, already fixed this and made the script more complex with the help of your reply