Invalid argument #1 to 'find' (table expected, got nil)

Cant seem to figure out how to fix the error. Been looking around at other people with same issue and havent had any luck. Any help is appreciated. I – where the error is


    local ReplicatedStorage = game:GetService("ReplicatedStorage")
    local swords = require(ReplicatedStorage:WaitForChild("SwordShop"))
    local player = game:GetService("Players").LocalPlayer
    local getDataFunc = ReplicatedStorage:WaitForChild("GetData")
    local interactItemFunc = ReplicatedStorage:WaitForChild("InteractItem")
    local gui = script.Parent
    local exit = gui.GuiShop.Button
    local points = gui.GuiShop.PT.Points
    local limit = gui.GuiShop.PT.Limit
    local itemsFrame = gui.GuiShop.TowerShop.ItemsFrame

    local playerData = {}

    local function getItemStatus2(itemName)  -- i get the error on this line
	if table.find(playerData.SelectedSword, itemName) then
		return "Equipped"
	elseif table.find(playerData.OwnedSwords, itemName) then
		return "Owned"
	else
		return "For Sale"
	end
    end

    local function interactItem(itemName)
	local data = interactItemFunc:InvokeServer(itemName)
	if data then
		playerData = data
		updateItems()
	end
    end
    function updateItems()
	points.Text = "Points : " .. playerData.Points
	for i, sword in pairs(swords) do
		
		local oldButton = gui.GuiShop.TowerShop:FindFirstChild(sword.Name)
		if oldButton then
			oldButton:Destroy()
		end
		local newButton = itemsFrame:Clone()
		newButton.Name = sword.Name
		newButton.TowerName.Text = sword.Name
		newButton.Price.Text = sword.Price .. " Points"
		newButton.Image.Image = sword.ImageAsset
		newButton.Desc.Text = sword.Description
		newButton.Type.Text = sword.Type
		newButton.Visible = sword.Visible
		newButton.LayoutOrder = sword.Price
		newButton.Parent = gui.GuiShop.TowerShop
		
		local status = getItemStatus2(sword.Name)
		if status == "For Sale" then
			newButton.Status.Text = "PURCHASE"
		elseif status == "Equipped" then
			newButton.Status.Text = "EQUIPPED"
			newButton.Price.Visible = false
			newButton.PriceLabel.Visible = false
		else 
			newButton.Status.Text = "EQUIP"
			newButton.Price.Visible = false
			newButton.PriceLabel.Visible = false
		end
		newButton.Status.Activated:Connect(function()
			interactItem(sword.Name)
		end)
	
	end
     end

     local function toggleShop()
	gui.GuiShop.Visible = not gui.GuiShop.Visible
	if gui.GuiShop.Visible then
		playerData = getDataFunc:InvokeServer()
		updateItems()	
	end
    end

    local function setupShop()

	local prompt = Instance.new("ProximityPrompt")
	prompt.RequiresLineOfSight = false
	prompt.ActionText = "Shop"
	prompt.Parent = workspace:WaitForChild("ShopPart2")
	
	prompt.Triggered:Connect(toggleShop)
	exit.Activated:Connect(toggleShop)
    end

    setupShop()
1 Like

Try adding these two lines under

playerData.SelectedSword = {}
playerData.OwnedSwords = {}

Still getting the same error with it

Try adding print(playerData) before the table.find. Show me what’s printed.

                ["OwnedTowers"] =  β–Ά {...},
                ["Points"] = 149656,
                ["SelectedTowers"] =  β–Ά {...}

Thats what it printed and got the same error but for some reason only prints the towers tables and not the swords tables