I want to create an array that has data stored in its 0 index but whenever I load the data it prints nil. I don’t know how to explain it very well so I’ll give an example script.
local DataStore = game:GetService("DataStoreService"):GetDataStore("Test")
game.Players.PlayerAdded:Connect(function(player)
local data = DataStore:GetAsync(player.UserId)
print("Data Loaded!")
if data ~= nil then
print(data[0]) --array[0] always prints nil
print(data[1]) --the other indexes saved their data successfully though
print(data[2])
end
end)
game.Players.PlayerRemoving:Connect(function(player)
local array = {
10,
200,
}
array[0] = 2
print(array[0]) --array[0] prints successfully here
DataStore:SetAsync(player.UserId, array)
print("Data Saved!")
end)
game:BindToClose(function()
wait(2)
end)
I’m trying to add the type of value in the 0 index so that it isn’t shown when you loop through the data with ipairs but I can still access it. For example I could set 0 index to “StringValue” and then load the rest of the data in the array as a string value and parent it to the player.