How to find items in a table?

Hi there, I am currently working on a game that needs titles. To keep things simple, I have put every thing in a table and dictionaries. My problem is that my script doesn’t seem to be finding the items in the table, but rather the items in the dictionary.

This is my code:

local titles = {
	
	IamACoolGuy_1230 = {
		
		colour = Color3.fromRGB(255, 185, 8), -- Colour of text outline
		text = "Head Developer", -- Text in the title
		ontop = true, -- Always ontop
		
	},
	
}

game.Players.PlayerAdded:Connect(function(player)
	if table.find(titles, player.Name) then
		print("Found")
	end
end)

This isn’t however printing found. I have tried looping though the table with a for loop, but when I print out v in the loop, it prints all the items in the dictionary, instead of in the table.

Any help is greatly appreciated!

1 Like

In the loop, because you hae a dictionary, your key/name in the dictionary would be the i, table.find doesn’t work with dictionaries, so you’d have to do

game.Players.PlayerAdded:Connect(function(player)
	for key, val in pairs(titles) do
		if key ~= player.Name then continue end
		--Do stuff
		break
	end
end)
1 Like

Oh ok, this helps a lot - thank you!

1 Like

Anytime! If you have anymore issues don’t be afraid to make another post!

1 Like