Hey I’m not sure what I’m doing wrong here, but I’m trying to get a key from the datastore and it’s saying that it’s nil.
local Work = DataStore:GetDataStore("Classwork")
local function createCode(Player, code)--receives the code
local code = code
members = Classes:GetAsync(code)--Check if the code is already in use
if not members then
Classes:SetAsync(code, {Owner = Player.UserId, Members = {}})
Work:SetAsync(code, {work = {}})--This is the one I'm having trouble with
local StringValue = Instance.new("StringValue")
StringValue.Name = code
StringValue.Value = code
StringValue.Parent = Player.OwnedClasses
print("There are no members")
return true
else
--Tell the user the code is taken, class codes must be unique
return false
end
end
local function addWorkToClass(player,code,subject)--receives the player's name, code and the subject/course
print(code)--prints the correct code
if player.OwnedClasses:FindFirstChild(code) then--if the player owns the class then
members = Work:GetAsync(code)--Check to see if the code is actually a code
print(members)--prints nil
if members then--if it's a code then
print("it's an actually code")
members:UpdateAsync(code, function(members)
table.insert(members, subject)--in the work table insert the subject/course
print("firing back to the client")
ReplicatedStorage.AddWorkToClassClient:FireClient(player,subject)--fire a back to the client
end)
else
print("it's not a code")
end
end
end
“it’s not a code” will always print. If I do…
members = Classes:GetAsync(code)
if members then
…it works, so I’m not sure why it won’t work with Work.
Thanks