NotZylon
(shiesty)
March 17, 2021, 1:26am
#1
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
NotZylon
(shiesty)
March 17, 2021, 1:36am
#3
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
NotZylon
(shiesty)
March 17, 2021, 1:39am
#5
what do you mean “message?”
decodedData, Sorry I was not clear
NotZylon
(shiesty)
March 17, 2021, 1:42am
#7
so i checked the replicateddata folder for the player and found out there was no decodedData
That’s why InventoryStore:OnUpdate function gave nil as the argument
NotZylon
(shiesty)
March 17, 2021, 1:45am
#9
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
NotZylon
(shiesty)
March 17, 2021, 1:50am
#11
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
NotZylon
(shiesty)
March 17, 2021, 1:59am
#13
but isn’t that what i had in the beginning?
No you had no data or nil, not an empty lua table
NotZylon
(shiesty)
March 17, 2021, 2:02am
#15
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
NotZylon
(shiesty)
March 17, 2021, 2:03am
#18
and where would i put that table?
NotZylon
(shiesty)
March 17, 2021, 2:04am
#19
This is the part of the error
inventoryString.Value = HttpService:JSONEncode(decodedData)
inventoryString.Value = HttpService:JSONEncode({})