Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
COMMUNITY QUESTION

Table does not working with table.find condition?

Hi, i have make a list of a boss in my server, when a player attack a boss i want to check if the specific boss is in the list, i have make this:

local list = {
    "Fox",
    "Yeti",
    "Crocodile",
    "Pharaoh"
}

When the player attack the boss i have this condition:

if table.find(list, HitParent) then
	print("Rangeboss")

HitParent = the name of the boss when the player attack, so for exemple HitParent = Fox

But the print is’nt fire ^^ maybe my condition is not exactly, somebody have a solution for check the name of the boss in the list ?

1 comment

1

It's probably not the table.find part, maybe it's something else with your code? Try posting the whole thing so we can check if there's an error somewhere that's causing it to not print.

3 answers

Use a for loop to search if the item is in the array. For example, you can do something like this:

for i,v in pairs (list) do
	if v == hitParent then
		print("Hit boss")
	end
end

Hope this helped!

2 comments

0

Not Working, the print isn't fire :/

0

for i,v in pairs (list) do if v == hitParent then print("Hit boss") else print("Not on the list") end end

for this to work, HitParent must be a string value and you can do this:

for i,v in pairs(list) do
	if v == HitParent then
		print"hello"
	end
end

1 comment

0

also table.find() does not exist in lua

if list[HitParent] then print(HitParent) end

This discussion is preserved as it was. New answers, comments, and votes are closed.