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

JSON string keeps giving me "null" or "[]", how do I fix this?

Asked by 5 years ago

Hello, I am trying to make a system that saves various values. I thought of doing that by combining all values in a JSON string, and tried that. The problem was that the JSON kept giving me null.

A bit of context, the player has a folder in it named "Stats". That folder has another folder in it called Coins. Inside of coins are a bunch of "accroutements" that all have a different name.

local httpservice = game:GetService("HttpService")
game.Players.PlayerRemoving:Connect(function(player)
local stats = player.Stats
local CollectedCoins = {}
for i,v in pairs(stats.Coins:GetChildren()) do
table.insert(CollectedCoins, v.Name)
end
local JSON = httpservice:JSONEncode(CollectedCoins)
print(JSON)
end)

My problem is that this keeps giving me null or "[]" in the output, and I have no idea why. the JSON string also includes other tables that work pretty much the same as the CollectedCoins one. Does anyone know why this is and how to solve it?

Thanks for your time.

Almost forgot to mention, this is a ServerScript located in ServerScriptService

0
+ When trying to print any of the children in the "Coins" folder, it will give me nil. Even though they're an accroutement/accesory Theroofypidgeot 21 — 5y
0
Yeah I am having the same problem^ GodOf_Lua 25 — 5y

Answer this question