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

for i,v in pairs problem?

So I'm trying to remove the part that matches the names in the table "items" but it just removes my head??

local items = {"Slab","Plate","Wall","CornerWall"}
local person = script.Parent.Parent.Character:GetChildren()
function mainmod:RemoveItems()
	for i, v in pairs (person) do
		if v.Name == items[1] or items[2] or items[3] or items[4] then
			v.Parent = script.Parent.Refrences
			print(v.Name.."Removed")
			break
		end
	end
end

3 comments

1

Your problem is line 5; The 'if' statement is only checking if the name is equal to a String within the list (items[1]), but when not, it is only checking if the Strings other than items[1] in the Table, are within it. :P

0

Therefore... if v.Name == items[1] or v.Name == items[2] or v.Name == items[3] or v.Name == items[4] then

0

Or... if v.Name == items[i] then

1 answer

I believe this should fix it:

local items = {"Slab","Plate","Wall","CornerWall"}
local person = script.Parent.Parent.Character:GetChildren()

function mainmod:RemoveItems()
    for i, v in pairs (person) do
        if v.Name == items[1] or v.Name == items[2] or v.Name == items[3] or v.Name == items[4] then
            v.Parent = script.Parent.Refrences
            print(v.Name.."Removed")
            break
        end
    end
end

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