You need to directly index it into the table, Like this: Pets["PetName"]
By using table.insert(), It will only add indexes using numbers and not strings, So that’s why you need to directly index it. That’s what an example code about it would look like:
I already gave you an example of how you would do it. You simply need to do Pets["Name"] (Replace name with the Name of the Pet) and make it a table with all the Properties that you want.
Yes, That’s how you would do it. You can also remove table.insert(pets, v.Name) (As when you declared it on the line below it’ll automatically insert it)
local DTS = game:GetService("DataStoreService")
local petData = DTS:GetDataStore("petdatastpre")
game.Players.PlayerAdded:Connect(function(plr)
local petsFolder = Instance.new("Folder",plr)
petsFolder.Name = "PetsFolder"
local success,errorMessage = pcall(function()
petData:GetAsync(plr.UserId)
end)
if success then
print(petData:GetAsync(plr.UserId))
else
print("u no have data")
end
end)
game.Players.PlayerRemoving:Connect(function(plr)
if plr:FindFirstChild("PetsFolder") then
local pets = {}
for i, v in pairs(plr["PetsFolder"]:GetChildren()) do
if v:IsA("Folder") then
if v:FindFirstChild("PetID") and v:FindFirstChild("EquipValue") then
table.insert(pets,v.Name)
pets[v.Name] =
{
["PetID"] = v.PetID.Value,
["EquipValue"] = v.EquipValue.Value
}
else
print("Error Saving Pet")
end
else
end
end
petData:SetAsync(plr.UserId,pets)
else
print("Error")
end
end)
game.Players.PlayerRemoving:Connect(function(plr)
if plr:FindFirstChild("PetsFolder") then
local pets = {}
for i, v in pairs(plr["PetsFolder"]:GetChildren()) do
if v:IsA("Folder") then
if v:FindFirstChild("PetID") and v:FindFirstChild("EquipValue") then
pets[v.Name] = {
["PetID"] = v.PetID.Value,
["EquipValue"] = v.EquipValue.Value
}
else
print("Error Saving Pet")
end
else
end
end
petData:SetAsync(plr.UserId,pets)
else
print("Error")
end
end)