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

[UPDATE] Can I get help with making the whole body of an npc flash, not just the head? thnx.

Asked by 4 years ago
Edited 4 years ago
while wait() do
    script.Parent.Head.Transparency = 1
    wait(5)
    script.Parent.Head.Transparency = 0
    wait(5)
end

so this is what we had for the head, is there a way to make it affect the whole body, not just the head?

1 answer

Log in to vote
0
Answered by 4 years ago
Edited 4 years ago

You can use an in pairs loop. a pairs loop is a loop where it loops through tables or arrays. You can use this to efficiently make the code shorter.

local NPCArray = script.Parent:GetChildren() --GetChildren() gets the children of the Parent.

while wait() do --This wait just make sures that the scirpt doesn't break.
    for _, v in pairs(NPCArray) do --Loops through the table
        if v:IsA("BasePart") then --IsA is self-explanatory. Is it a Part?
            v.Transparency = 1 --Set transparency to 1
        end
    end
    wait(5)
    for _, v in pairs(NPCArray) do
        if v:IsA("BasePart") then
            v.Transparency = 0
        end
    end
    wait(5)
end

Source: Alvinblox In Pairs Loop

Ad

Answer this question