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

Datastore not finding key correctly?

Asked by 3 years ago

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)

0
Remove the `not` from line 7, it reverses the `val` value turning it into most likely `false` if the value is not `nil` or `false`. Also `UpdateAsync` takes 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. imKirda 4491 — 3y
0
@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 icymanred1 6 — 3y

Answer this question