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

How to check if something is not in a table?

See, what I'm trying to do is have a block be swung like a sword, and check if it's already hit that person to prevent from dealing mass amounts of damage.

Here is the basic script, without dealing any damage.

sword = script.Parent
mainpart = sword.Blade

hitplayers = {}

mainpart.Touched:connect(function(hit)
	if hit.Parent:FindFirstChild("Humanoid") and (hit.Parent.Name[hitplayers]) == nil then
		table.insert(hitplayers, hit.parent.Name)
	end
end)

Any ideas?

1 answer

You have to loop through the table.

function InTable(Tab,Val)
	for _,n in pairs(Tab) do
		if n == Val then
			return true
		end
	end
end

if not InTable({1,2,3,4},77) then
	print("HI")
end

1 comment

0

I think that works, thanks

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