Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
1

for i,v in pairs problem?

Asked by
NotSoNorm 777 Moderation Voter
8 years ago

Please make your question title relevant to your question content. It should be a one-sentence summary in question form.

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
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 TheeDeathCaster 2368 — 8y
0
Therefore... if v.Name == items[1] or v.Name == items[2] or v.Name == items[3] or v.Name == items[4] then Redbullusa 1580 — 8y
0
Or... if v.Name == items[i] then Redbullusa 1580 — 8y

1 answer

Log in to vote
-1
Answered by 8 years ago

Please provide explanation with your answers. Simply posting code does not spread knowledge of integral scripting processes which helps people understand the logic and reasoning behind your 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
Ad

Answer this question