how can I save tables in datastore then get that table and use it in a for loop? ex:
--this is my current code that does not work
--its also edited for simplicity
local plrPets = {}
for i,pet in pairs(player.Pets:GetChildren()) do
table.insert(plrPets, pet.Value) --the pets are stored in string values
end
datastore:SetAysnc("Pets_"..player.UserId, plrPets)
Getting the table:
local LoadedPets = {}
local success, err = pcall(function()
LoadedPets = datastore:GetAysnc("Pets_"..player.UserId)
end)
if success then
--add pets to folder
else
warn("Unable to load pets!")
end
Also there are no errors. And yes I know im doing something wrong but I dont know what so I’m asking here!
Have you tried a loop, like loop the function till an value or function is true or has acquired its reason like this is a simple example of it, and this just helps at debugging messy code or not very known code.
local Value = false
local RunService = game:GetService("RunService")
RunService.RenderStepped:Connect(function()
Value = true
end)
while not Value do
warn("Value is not true!")
end
You are putting the results of a GetChildren() call into a table and then trying to put that table into a datastore. You can’t save instances in a datastore. You will need to create a way of serializing the players’ pets, like converting them into a table of properties such as name, type, level, etc.