So I am currently trying to create a Data Store system that goes through a table and uses GetAsync() to retrieve the value of a player’s leaderboard stat. I’m doing this so that I don’t have to copy and paste lines of code whenever I want to add a new stat.
local dsService = game:GetService("DataStoreService")
local ds = dsService:GetDataStore("SavedStats")
local rs = game:GetService("ReplicatedStorage")
local remotes = rs:WaitForChild("REs")
local currencyRemote = remotes:WaitForChild("CurrencyCounter")
local intStats = {"Money"}
game.Players.PlayerAdded:Connect(function(plr)
local leaderB = Instance.new("Folder")
leaderB.Name = "leaderstats"
leaderB.Parent = plr
for i,stat in pairs(intStats) do
local addStat = Instance.new("IntValue")
addStat.Name = stat
addStat.Value = ds:GetAsync(plr.UserId):FindFirstChild(stat) or 0
addStat.Parent = leaderB
end
currencyRemote:FireServer(plr)
end)
game.Players.PlayerRemoving:Connect(function(plr)
ds:SetAsync(plr.UserId, {
["Money"] = plr.leaderstats.Money.Value;
})
end)
Here is the error occurring in the Output:
And then I checked the Dev Console in game:
I’m really lost as to what I should do, I’ve done everything. I’ve checked multiple other topics and watched multiple videos on Data Stores and etc. I’m a returning scripter, so I haven’t done anything like this in a while.