I have made a datastore script that checks if a key exists. if it does then it updates the datastore, if it doesnt find a key then it sets the datastore key but for some reason it is not finding the key at all. Here is the module script code
local module = {}
local datastoreservice = game:GetService("DataStoreService")
local inv = datastoreservice:GetDataStore('inventory')
function module.SetInventory(pid)
local val = inv:GetAsync(pid)
print(val)
if not val == nil then
print("The datastore was found")
table.insert(val,"A new datastore key!")
inv:UpdateAsync(pid,val)
else
print("NO key was found")
inv:SetAsync(pid,{" the first key"})
end
end
return module
here is the server side script
local invdata = require(game.ServerScriptService.datastoreinventory)
local datastoreservice = game:GetService("DataStoreService")
local inv = datastoreservice:GetDataStore('inventory')
invdata.SetInventory('babo')
wait(3)
local val = inv:GetAsync('babo')
print(val)

2 comments
Remove the
notfrom line 7, it reverses thevalvalue turning it into most likelyfalseif the value is notnilorfalse. AlsoUpdateAsynctakes in function as second parameter so on line 10 it will error. I, however, don't understand what do you want to achieve with it.@imKidra I want it to reverse it as It checks if the datastore key is empty or not. The update async updates the datastore key if it already exists