Hello Community,
I have a problem the output is saying at my table save script: "Attempt to index upvalue of "Pets" (A nil value) how could I fix this?
My script:
local PetSave = game:GetService("DataStoreService"):GetDataStore("Pets")
local Pets = {}
local Number = 1
game.Players.PlayerAdded:Connect(function(Player)
local PetsFolder = Instance.new("Folder")
PetsFolder.Name = "Pets"
PetsFolder.Parent = Player
local Key = Player.UserId
Pets = PetSave:GetAsync(Key)
end)
game.Players.PlayerRemoving:Connect(function(Player)
for index = 1, #Pets do
table.remove(index)
for _,p in pairs (Player.Backpack:GetChildren()) do
table.insert(Pets, Number, p.Name, p.Value)
end
local Key = Player.UserId
PetSave:SetAsync(Pets, Key)
print("savedi")
end
end)

1 comment
It's probably because there's nothing in the "Pets" table.