Im trying to save a table and I did this
the script is basically supposed to print 10 more of every value but instead it prints 0 everytime
local DataStore = game:GetService("DataStoreService"):GetDataStore('TestingStore')
local Tabl = {
Cash = 0,
Gold =0,
Diamonds = 0
}
function IncrementTable(Val)
Val = Val + 10
end
function LoopToPrint(Table)
for i,v in pairs(Table) do
print(v)
end
end
game.Players.PlayerAdded:Connect(function(plr)
DataStore:GetAsync(plr.UserId)
LoopToPrint(Tabl)
end)
game.Players.PlayerRemoving:Connect(function(plr)
IncrementTable(Tabl.Cash)
IncrementTable(Tabl.Diamonds)
IncrementTable(Tabl.Gold)
LoopToPrint(Tabl)
DataStore:SetAsync(plr.UserId,Tabl)
end)

1 comment
Look into something called Pcall it run re-run the function if there was an error mainly used for datastores