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

Check if a string is not part of an array?

For some reason this code doesn't work. Is there another way?

It's supposed to do the 'stuff' to everything (from i, v in pairs) as long as it's name is not whatever is in the list.

if v.Name ~= {"PrimaryPart", "Head", "HumanoidRootPart"} then
	-- stuff
end

1 answer

✓ Accepted answer

Well what your doing is comparing a string to a table, if you want to check if a string is inside a table we will have to go through each one and check individually

local t = {"PrimaryPart", "Head", "HumanoidRootPart"}

local checkname="string"

local isin=false
for _,v in pairs(t) do
	if v==checkname then
		isin=true
	end
end
if isin==true then
	print('run')
end

Here I set up a variable and then made a for loop to go through each string in the table, if the current string is the same as the string we are checking it makes a bool variable true.

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