Hi, I'm trying to Datastore a table with the "For", but it doesn't work. Can you help me please?
local SaveT = {"Example1","Example2","Example3"}
local DS = game:GetService("DataStoreService"):GetDataStore("DatastoreExample")
local number = 1
game.Players.PlayerAdded:Connect(function(plr)
local leaderstats = Instance.new("Folder",plr)
leaderstats.Name = "leaderstats"
local key = "id-"..plr.userId
local savedvalues = DS:GetAsync(key)
for _, v in pairs(SaveT) do
local nstance = Instance.new("IntValue",leaderstats)
nstance.Name = v
if savedvalues then
v = savedvalues[number]
number = number + 1
else
local NFS = {v.Value}
DS:GetAsync(key,NFS)
end
end
end)
game.Players.PlayerRemoving:Connect(function(plr)
local key = "id-"..plr.userId
for _, v in pairs(SaveT) do
DS:SetAsync("plr.leaderstats."..v..".Value")
end
end)
What's the problem here?
