Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
0

HttpService:JSONEncode of a table only [Null] as a result? How to fix?

Asked by 5 years ago

I actually tried this script so now it dosen't saves so I tried to get the string of the HttpServiceJSON and it was [Null] how can I fix?

local DS = game:GetService("DataStoreService")

local PetDS = DS:GetDataStore("PetDataStore")

local PetsTable = {}

local AUTOSAVE_INTERVAL = 60



game.Players.PlayerAdded:Connect(function(Player)

local PetsFolder = Instance.new("Folder")

PetsFolder.Name = "Pets"

PetsFolder.Parent = Player

local key = Player.UserId

print(key)

PetsTable = PetDS:GetAsync(key)

if PetsTable then

print(PetsTable)

PetsTable = game:GetService("HttpService"):JSONDecode(PetsTable)

for _,p in pairs (PetsTable) do

local In = Instance.new("IntValue")

In.Name = p["Name"]
In.Parent = PetsFolder

In.Value = p["Value"]

end

end

end)



game.Players.PlayerRemoving:Connect(function(Player)

PetsTable = {}

local key = Player.UserId

print(key)

for _,i in pairs (Player.Pets:GetChildren()) do

if i then

table.insert(PetsTable,i)

PetsTable[i] = {}

table.insert(PetsTable[i],"Name")

table.insert(PetsTable[i], "Value")

PetsTable[i]["Name"] = i.Name

PetsTable[i]["Value"] = i.Value

print(PetsTable[i]["Name"])

end

end

local NewPetsTable = game:GetService("HttpService"):JSONEncode(PetsTable)

print(NewPetsTable)

PetDS:SetAsync(key, NewPetsTable)

warn("Saved!")

end)

Thanks for answers!

Answer this question