"Argument 1 missing or nil"

So im using datastore2 and im confused what this means.
Update inventory script:

local event = game.ReplicatedStorage.Events:WaitForChild("UpdateInventory")
local datastore2 = require(game.ServerStorage:WaitForChild("DataStore2"))
event.OnServerEvent:Connect(function(player)
local inventorystore = datastore2("Inventory", player)
	inventorystore:Update(function(currentTable)
	end)
end)

DataHandler error part

InventoryStore:OnUpdate(function(decodedData, player)
		inventoryString.Value = HttpService:JSONEncode(decodedData) --Error here
	end)

its because the decoded data turned out to be nil so it assumes that you gave no argument and errors

is there anyway i could fix this?

You could check if the message was nil and if it was you could pass on an empty table instead

what do you mean “message?”

decodedData, Sorry I was not clear

so i checked the replicateddata folder for the player and found out there was no decodedData
Screen Shot 2021-03-16 at 8.42.29 PM

That’s why InventoryStore:OnUpdate function gave nil as the argument

So what may i do to fix this issue? Because im clueless on what to do

You could check if the decoded data given turned out to be nil. And if it was you could use the default data as the argument to give to the JSONEncode function

default data? Sorry, im not really good at datastore2, how do i give it to the JSONEncode function, its my first time so im just learning

Its ok, just use an empty table as the default data

but isn’t that what i had in the beginning?

No you had no data or nil, not an empty lua table

how do you get an empty lua table? (again im really sorry if im being a pain)

A lua table can be made like this local table = {}

You do not need JSONEncode for your data. Roblox does this process automatically, so doing it yourself will slow the script down and might error. Also, for the first function parameter for the :Update function, make sure you return the data you want. Also, which line is the error on?

1 Like

and where would i put that table?

This is the part of the error

inventoryString.Value = HttpService:JSONEncode(decodedData)

inventoryString.Value = HttpService:JSONEncode({})