Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
0

Saving Table to datastore won't work but there are no errors?

Asked by 5 years ago

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)
0
Look into something called Pcall it run re-run the function if there was an error mainly used for datastores Arkrei 389 — 5y

1 answer

Log in to vote
0
Answered by 5 years ago

You never set Tabl to the table you loaded on join. See on line 25 where you haven't assigned the function result to a variable? That's your problem.

Ad

Answer this question