Table.Find not working

Hello everyone.

I have a script using Table.Find below:

if table.find(Tools, OtherReq[count]) then
	print("yes")
end

Tools is equal to player.Backpack:GetChildren(), and OtherReq is equal to {“Apple”}.

I have double checked this by printing both tables before the if then statement, and they are functioning as intended - In tools, there are apples in the table.

However, the script after it never runs, nor does it print (“yes”). Why is this happening?

1 Like

Tools is an array of Roblox objects (instances) and OtherReq is an array of string values.

3 Likes

Adding to what Forummer has said above,
What is ‘count’?

1 Like

Thanks, but how would I change the array of instances into just their names, string values?

1 Like

For this, you can just use FindFirstChild, which will search the given instance for a child of the provided name.

local tool = player.Backpack:FindFirstChild(OtherReq[count])
if tool then
    print("yes")
    -- tool now contains the Tool instance in the Backpack
end
3 Likes

You could do table.find(Tools, table.find(Tools, OtherReq[Count]), because table.find requires at least 2 arguments, the table itself and the index of the object in the same table.