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

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

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

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

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