I did this DataStore Script but it's not working could someone please help me? im trying to do "table.insert()" and I dont know why not working
local DataService = game:GetService("DataStoreService")
local DS = DataService:GetDataStore("DATASTORE")
game.Players.PlayerAdded:Connect(function(player)
local Folder = Instance.new("Folder",player)
Folder.Name = "leaderstats"
local Cash1 = Instance.new("IntValue",Folder)
Cash1.Name = "Gold"
local Lv1 = Instance.new("IntValue", Folder)
Lv1.Name = "Level"
local Stats = DS:GetAsync(player.UserId)
if Stats == not nil then
Cash1.Value = Stats[1]
Lv1.Value = Stats[2]
else
Cash1.Value = 0
Lv1.Value = 1
end
end)
game.Players.PlayerRemoving:Connect(function(player)
local Save = {}
table.insert(Save, player.leaderstats.Gold.Value)
table.insert(Save, player.leaderstats.Level.Value)
DS:SetAsync(player.UserId, Save)
end)

2 comments
I've used some methods such as pcall, you may want to investigate that global function some more for this type of stuff because it's pretty important for this case.
thx!! it worked. Thx so much!