I am trying to make a system that saves two values in a table (the values in the table are from leaderstats). The problem I am having is that I don’t know if I am doing it right.
Here is my code:
local DDS = game:GetService("DataStoreService"):GetDataStore("DataThingy")
local leaderstatsInTable = {
Levels = 0,
Experience = 0
}
game.Players.PlayerAdded:Connect(function(Plr)
local stats = Instance.new("Folder", Plr)
stats.Name = "leaderstats"
local levels = Instance.new("IntValue", stats)
levels.Name = "Levels"
local exp = Instance.new("IntValue", stats)
exp.Name = "Exp"
leaderstatsInTable.Levels = levels.Value
leaderstatsInTable.Experience = exp.Value
local data
local suc, err = pcall(function()
local data = DDS:GetAsync("key_"..Plr.UserId)
end)
if not suc then
warn(err)
else
levels.Value = data.Levels
exp.Value = data.Experience
end
end)
game.Players.PlayerRemoving:Connect(function(plr)
local data
local suc, err = pcall(function()
local data = DDS:SetAsync("key_"..plr.UserId, leaderstatsInTable)
end)
if not suc then
warn(err)
end
end)
I hope you can find the error.