Attempt to Index Boolean

So, I’m trying to make a code joining system. But I’m getting the error

11:02:04.068 - ServerScriptService.ClassesDataStore:28: attempt to index boolean with ‘Members’

The error is happening at this line table.insert(members.Members, Player.UserId)

Script

local function createCode(Player, code)
	local code = code-- Code is what the player types into the textBox
	
	members = Classes:GetAsync(code)--Check if the code is already in use
	if not members then
		Classes:SetAsync(code, {Owner = Player.UserId, Members = {}})
		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 joinClass(Player, code)
	local code = code--Code is what the player types into the textBox
	
	members = Classes:GetAsync(code)--Check to see if it's a real code
	if members then --If it's a real code then
		Classes:UpdateAsync(code, function(members)
			table.insert(members.Members, Player.UserId) -- Player being the one joining
			return true
		end)
	else
		print("no members")
		return false
	end
end

ReplicatedStorage.CreateCode.OnServerInvoke = createCode
ReplicatedStorage.JoinClass.OnServerInvoke = joinClass

Thanks and have a great rest of your day! :grinning:

It means that members is equals to true or false and you’re trying to use table.insert on a boolean.
What does Classes:GetAsync(code)return?

1 Like

Classes:UpdateAsync updates the current value of code.
When you return true it sets code to a boolean.

Try using

Classes:UpdateAsync(code, function(members)
        local newmembers = newmembers
	table.insert(newmembers, Player.UserId) -- Player being the one joining
	return newmembers
end)
2 Likes

What about the creating code part?

This is my local script. How would I check to see if it was successfully created if I can’t return true?

local success 
		success = createCode:InvokeServer(code)
		
		
		if success then 
			ReplicatedStorage.AddClass:FireServer(success)
			local Class = script.Class:Clone()
			Class.Text = code
			Class.Name = code
			Class.Parent = script.Parent.Parent.Parent.Parent.Classes:FindFirstChild("Classes").ScrollingFrame
			textbox.Text = ""
			script.Parent.Parent.Visible = false
		else
			textbox.Text = "Code Already Taken"
		end

You don’t need to return true inside the update function.
You can do it after.

if members then --If it's a real code then
		Classes:UpdateAsync(code, function(members)
			local newmembers = newmembers
			table.insert(newmembers, Player.UserId) -- Player being the one joining
			return newmembers
		end)
        return true
	else
		print("no members")
		return false
	end
2 Likes