Adding onto a Data store array

I am trying to add onto an array stored in the DataStore yet when I insert 1 into the Array the output of the NewArray is nil. I know I must be missing something quite obvious yet I have been unable to solve this for some time now. Help is much appreciated, thanks.

Example:

    -- Player is correctly defined.  
    local DataStore = game:GetService("DataStoreService"):GetDataStore("Data")
    DataStore:SetAsync(Player.UserId, {})
    local Array = DataStore:GetAsync(Player.UserId)
    local NewArray = table.insert(Array, 1) -- Output is nil
    DataStore:SetAsync(Player.UserId, NewArray)
1 Like

table.insert doesn’t return the table, it just modifies the given table

table.insert(Array, 1)
DataStore:SetAsync(Player.UserId, Array)

2 Likes

I knew it would be something obvious :joy:; wonder why I overlooked that multiple times.

Thanks for the help.

1 Like