Checking if a table has the same strings as another table

Hello!!
I have gotten myself into a tricky spot while creating a bingo system…
Ive made everything without any major issues but this part of the script

For easier understanding, I will quickly go over how this system works…
Basically, when the player has a number on their bingo card that has been picked by a RNG, it fires a BindableEvent to this script which then checks if the number is a bingo number, which has a redish colour to it, if it does then it will put that number into the table BingoNum.
After that it checks if BingoNum match ones of the tables inside of BingoType
This is where im having issues as Im not sure on how to go about making that part

the script
--// Services
local RS = game:GetService("ReplicatedStorage")
local Players = game:GetService("Players")

--// Variables
local BC = game.ServerStorage.ServerEvents.BingoCheck
local BingoTypes = {
	Bingo1 = {"1", "2", "3", "4", "5"},
	Bingo2 = {"6", "7", "8", "9", "10"},
	Bingo3 = {"11", "12", "13/FREE", "14", "15"},
	Bingo4 = {"16", "17", "18", "19", "20"},
	Bingo5 = {"21", "22", "23", "24", "25"},
	Bingo6 = {"1", "6", "11", "16", "21"},
	Bingo7 = {"2", "7", "12", "17", "22"},
	Bingo8 = {"3", "8", "13/FREE", "18", "23"},
	Bingo9 = {"4", "9", "14", "19", "24"},
	Bingo10 = {"5", "10", "15", "20", "25"},
}

--// Script
BC.Event:Connect(function(Player, NumList)
	local textLabelContainer = {} --stores all the numbers the player has
	local BingoNum = {} --stores the numbers that have been picked that the player has

	for i,v in pairs(NumList:GetChildren()) do --gets the numbers the player has
		if v.Name == "UIGridLayout" then continue else
			table.insert(textLabelContainer, v)
		end
	end 

	for i = 1, 25 do --gets the numbers the player has that has been called out
		if textLabelContainer[i].TextColor3 == Color3.fromRGB(249, 88, 88) then
			table.insert(BingoNum, textLabelContainer[i])
		end
	end

-- this is where im having issues making
	for key, bingo in BingoTypes do
		for i, v in BingoNum do
			if BingoNum[v] == bingo then
				print("hello") -- trying to see if BingoNum has strings that Bingo1,2,3,etc also has
			end
		end
	end
end)

Any and all help is appreciated

You’re using “v” as the index, but it should be “i” to retrieve that index in the BingoNum table. Alternatively, you can compare the values, e.g.

v == bingo
1 Like

Still doesnt work, didnt mean to have v in the post, my bad

Could you explain about comparing the values?

for key,bingo in pairs(BingoTypes) do
for i,v in pairs(bingo) do
if table.find(BingoNum,v) then
print("hello")
end
end
end
1 Like

doesnt seem to print

3O

it works fine.
are you sure that “BingoNum” table isn’t empty and it has a similar number in the BingoTypes Table?

local BingoTypes = {
Bingo1 = {"1","2","3"},
Bingo2 = {"5","6","7"}
}
local BingoNum = {"6"}
for key,bingo in pairs(BingoTypes) do
	for i,v in pairs(bingo) do
		if table.find(BingoNum,v) then
			print("hello")
		end
	end
end
-- Output : hello
1 Like

Yeah they are the same
image

Also, im trying to see if BingoNum has all the numbers a BingoTypes table has not just one

local BingoTypes = {
	Bingo1 = {"1","2","3"},
	Bingo2 = {"5","6","7"}
}
local BingoNum = {"1","2","3"}
for key,bingo in pairs(BingoTypes) do
	if table.concat(bingo) == table.concat(BingoNum) then
		print("hello")
	end
end
1 Like

I get this error

can you show me your code?

tt

1 Like
--// Services
local RS = game:GetService("ReplicatedStorage")
local Players = game:GetService("Players")

--// Variables
local BC = game.ServerStorage.ServerEvents.BingoCheck
local BingoTypes = {
	Bingo1 = {"1", "2", "3", "4", "5"},
	Bingo2 = {"6", "7", "8", "9", "10"},
	Bingo3 = {"11", "12", "13/FREE", "14", "15"},
	Bingo4 = {"16", "17", "18", "19", "20"},
	Bingo5 = {"21", "22", "23", "24", "25"},
	Bingo6 = {"1", "6", "11", "16", "21"},
	Bingo7 = {"2", "7", "12", "17", "22"},
	Bingo8 = {"3", "8", "13/FREE", "18", "23"},
	Bingo9 = {"4", "9", "14", "19", "24"},
	Bingo10 = {"5", "10", "15", "20", "25"},
}

--// Script
BC.Event:Connect(function(Player, NumList)
	local textLabelContainer = {}
	local BingoNum = {}

	for i,v in pairs(NumList:GetChildren()) do
		if v.Name == "UIGridLayout" then continue else
			table.insert(textLabelContainer, v)
		end
	end 

	for i = 1, 25 do
		if textLabelContainer[i].TextColor3 == Color3.fromRGB(249, 88, 88) then
			table.insert(BingoNum, textLabelContainer[i])
		end
	end
	for key,bingo in pairs(BingoTypes) do
		if table.concat(bingo) == table.concat(BingoNum) then
			print("hello")
		end
	end
end)

I think ur trying to compare instances with strings

Try to change table.insert(BingoNum, textLabelContainer[i])
with table.insert(BingoNum, textLabelContainer[i].Name)

1 Like

Your BingoNum value is an object value not a string. I wrote down the solution for you.

--// Services
local RS = game:GetService("ReplicatedStorage")
local Players = game:GetService("Players")

--// Variables
local BC = game.ServerStorage.ServerEvents.BingoCheck
local BingoTypes = {
	Bingo1 = {"1", "2", "3", "4", "5"},
	Bingo2 = {"6", "7", "8", "9", "10"},
	Bingo3 = {"11", "12", "13/FREE", "14", "15"},
	Bingo4 = {"16", "17", "18", "19", "20"},
	Bingo5 = {"21", "22", "23", "24", "25"},
	Bingo6 = {"1", "6", "11", "16", "21"},
	Bingo7 = {"2", "7", "12", "17", "22"},
	Bingo8 = {"3", "8", "13/FREE", "18", "23"},
	Bingo9 = {"4", "9", "14", "19", "24"},
	Bingo10 = {"5", "10", "15", "20", "25"},
}

--// Script
BC.Event:Connect(function(Player, NumList)
	local textLabelContainer = {} --stores all the numbers the player has
	local BingoNum = {} --stores the numbers that have been picked that the player has
    local Found

	for i,v in pairs(NumList:GetChildren()) do --gets the numbers the player has
		if v.Name ~= "UIGridLayout" then
			table.insert(textLabelContainer, v)
		end
	end 

	for i = 1, #textLabelContainer do --gets the numbers the player has that has been called out
		if textLabelContainer[i].TextColor3 == Color3.fromRGB(249, 88, 88) then
			table.insert(BingoNum, textLabelContainer[i])
		end
	end

    for Key, BingoTable in pairs(BingoTypes) do
      if Found then break end
        for _, Value in ipairs(BingoNum) do
            if not table.find(BingoTable, tostring(Value)) then
                break
            end
            Found = BingoTable
        end
    end
    
    if Found then
        print("Hello")
    end
end)
1 Like

you’re inserting instances in the BingoNum Table it must be a String.

1 Like

Still doesnt print, even if i change it to .Text

This just prints hello everytime the event is fired

My bad I forgot something

--// Services
local RS = game:GetService("ReplicatedStorage")
local Players = game:GetService("Players")

--// Variables
local BC = game.ServerStorage.ServerEvents.BingoCheck
local BingoTypes = {
	Bingo1 = {"1", "2", "3", "4", "5"},
	Bingo2 = {"6", "7", "8", "9", "10"},
	Bingo3 = {"11", "12", "13/FREE", "14", "15"},
	Bingo4 = {"16", "17", "18", "19", "20"},
	Bingo5 = {"21", "22", "23", "24", "25"},
	Bingo6 = {"1", "6", "11", "16", "21"},
	Bingo7 = {"2", "7", "12", "17", "22"},
	Bingo8 = {"3", "8", "13/FREE", "18", "23"},
	Bingo9 = {"4", "9", "14", "19", "24"},
	Bingo10 = {"5", "10", "15", "20", "25"},
}

--// Script
BC.Event:Connect(function(Player, NumList)
	local textLabelContainer = {} --stores all the numbers the player has
	local BingoNum = {} --stores the numbers that have been picked that the player has
    local Found

	for i,v in pairs(NumList:GetChildren()) do --gets the numbers the player has
		if v.Name ~= "UIGridLayout" then
			table.insert(textLabelContainer, v)
		end
	end 

	for i = 1, #textLabelContainer do --gets the numbers the player has that has been called out
		if textLabelContainer[i].TextColor3 == Color3.fromRGB(249, 88, 88) then
			table.insert(BingoNum, textLabelContainer[i])
		end
	end

    for _, BingoTable in pairs(BingoTypes) do
      if Found then break end
        for Index, Value in ipairs(BingoNum) do
            if not table.find(BingoTable, tostring(Value)) then
                break
            end
            if Index == #BingoNum then
                Found = BingoTable
            end
        end
    end
    
    if Found then
        print("Hello")
    end
end)
1 Like

Doesnt seem to print now

o

I think it’s because you have more than 5 values in your BingoNum table. Try this.

--// Services
local RS = game:GetService("ReplicatedStorage")
local Players = game:GetService("Players")

--// Variables
local BC = game.ServerStorage.ServerEvents.BingoCheck
local BingoTypes = {
	Bingo1 = {"1", "2", "3", "4", "5"},
	Bingo2 = {"6", "7", "8", "9", "10"},
	Bingo3 = {"11", "12", "13/FREE", "14", "15"},
	Bingo4 = {"16", "17", "18", "19", "20"},
	Bingo5 = {"21", "22", "23", "24", "25"},
	Bingo6 = {"1", "6", "11", "16", "21"},
	Bingo7 = {"2", "7", "12", "17", "22"},
	Bingo8 = {"3", "8", "13/FREE", "18", "23"},
	Bingo9 = {"4", "9", "14", "19", "24"},
	Bingo10 = {"5", "10", "15", "20", "25"},
}

--// Script
BC.Event:Connect(function(Player, NumList)
	local textLabelContainer = {} --stores all the numbers the player has
	local BingoNum = {} --stores the numbers that have been picked that the player has
    local Found
    local Iterations = 0

	for i,v in pairs(NumList:GetChildren()) do --gets the numbers the player has
		if v.Name ~= "UIGridLayout" then
			table.insert(textLabelContainer, v)
		end
	end 

	for i = 1, #textLabelContainer do --gets the numbers the player has that has been called out
		if textLabelContainer[i].TextColor3 == Color3.fromRGB(249, 88, 88) then
			table.insert(BingoNum, textLabelContainer[i])
		end
	end

    for _, BingoTable in pairs(BingoTypes) do
        if Found then break end
        Iterations = 0
        for Index, Value in ipairs(BingoNum) do
            print(Iterations)
            if table.find(BingoTable, tostring(Value))
                Iterations += 1
            end
        
            if Iterations == #BingoTable then
                Found = BingoTable
                break
            end
        end
    end
    
    if Found then
        print("Hello")
    end
end)
1 Like

Sorry for the 2 hour wait on if this worked for me or not, just had to check if it fully worked with the bingo system.

Thank you very much for your help man, appreciate it alot…
Thanks to @Polyheximal, @richiitalia and @ayoub50 for their help aswell :DDD

2 Likes