which I am currently using with table.insert. I was saving the files I got from the player inventory into this table as UTF-8. but I noticed that only their names remain in the table. “PetHP” comes as 0,nil. what is the reason of this? How can I fix? Thank you very much for your help
I’m posting screenshots
this one gets the player’s folder and inserts them inside to data table

Note : The only error is in the datastore, “PetHP” remains at the correct value as long as I don’t get the data from the datastore.
here is the full script.
local pl,wk,rn,db,prt,ds,debounce,ht = game:GetService("Players"),game:GetService("Workspace"),game:GetService("RunService"),game:GetService("Debris"),script.Parent,game:GetService("DataStoreService"),true,game:GetService("HttpService")
local dts = ds:GetDataStore("RaeStore")
pl.PlayerAdded:Connect(function(p)
local petfolder = Instance.new("Folder",p)
petfolder.Name = "PetFolder"
local sc,ms = pcall(function()
return dts:GetAsync("Pets"..p.UserId)
end)
if sc and ms then
for i,v in ipairs(ms.Pets) do
local newpetfl = Instance.new("Folder",petfolder)
newpetfl.Name = "Pet"
local newhealth = Instance.new("NumberValue",newpetfl)
newhealth.Value = v.PetHP
newhealth.Name = "PetHP"
print(v)
end
else
warn(tostring(ms))
end
end)
pl.PlayerRemoving:Connect(function(p)
local datats = {
["Pets"] = {
}
}
local petfolder = p:FindFirstChild("PetFolder")
for i,v in ipairs(petfolder:GetChildren()) do
if v:IsA("Folder") and string.find(v.Name,"Pet") then
local pethealth,namealgorithm = v:FindFirstChild("PetHP"),v.Name..i
local newpetfoldertosave = {
[tostring(namealgorithm)] = {
["PetHP"] = pethealth.Value
}
}
table.insert(datats.Pets,i,newpetfoldertosave)
end
end
local sc,ms = pcall(function()
return dts:SetAsync("Pets"..p.UserId,datats)
end)
if sc then
else
warn(tostring(ms))
end
end)
prt.Touched:Connect(function(h)
local c = h.Parent
if c and debounce then
local hm,p = c:FindFirstChild("Humanoid"),pl:GetPlayerFromCharacter(c)
if hm and p then
debounce = false
local petfolder = p:FindFirstChild("PetFolder")
local newpet,hp = Instance.new("Folder",petfolder),math.random(1,100)
newpet.Name = "Pet1"
petfolder.Name = "PetFolder"
local newpethealth = Instance.new("NumberValue",newpet)
newpethealth.Name = "PetHP"
newpethealth.Value = hp
wait(1)
debounce = true
end
end
end)
Edit : thats a part (im just testing it)
