I am trying to make an inventory system for my game. Right now I am trying to make it save. But it is saying that the GetSaved variable is nil and although it is nil, it still goes through the if statement.
local DSService = game:GetService('DataStoreService'):GetDataStore('NotTheActualKey123')
local HttpService = game:GetService('HttpService')
game.Players.PlayerAdded:connect(function(plr)
-- Define variables
local uniquekey = 'id-'..plr.userId
local plrFolder = Instance.new("Folder", plr)
plrFolder.Name = "Inventory"
local equippedFolder = Instance.new("Folder", plrFolder)
equippedFolder.Name = "Equipped"
local item = Instance.new("StringValue", equippedFolder)
item.Name = "Item"
-- GetAsync
local GetSaved = DSService:GetAsync(uniquekey)
if GetSaved ~= nil then
plrFolder = HttpService:JSONDecode(GetSaved[1])
else
local Inventoryfolder = plrFolder:GetChildren()
local NumbersForSaving = HttpService:JSONEncode(Inventoryfolder)
DSService:SetAsync(uniquekey, NumbersForSaving)
end
end)
game.Players.PlayerRemoving:connect(function(plr)
local Inventoryfolder = plr.Inventory:GetChildren()
local uniquekey = 'id-'..plr.userId
local Savetable = HttpService:JSONEncode(Inventoryfolder)
DSService:SetAsync(uniquekey, Savetable)
end)
Error in the output was from the online mode and the only error it gives me.
