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

Can this be any faster?

Asked by 8 years ago

Is there a way so you can make every part in a group be New yeller at the same time without using for i,v in pairs?

--I do this, if you have any tips or anything you want to point out to me that could make this be easier and better.

while true do
wait()
for i,v in pairs(script.Parent:GetChildren()) do
if v ~= script then
if v:IsA("BasePart") then
v.BrickColor = BrickColor.new("New Yeller")
end
end
end
end

2 answers

Log in to vote
3
Answered by 8 years ago
local p = script.Parent;
local bcl = BrickColor.new("New Yeller")
while wait() do
local c = p:GetChildren();
for i=1,#c do
if c[i]:IsA"BasePart" then
c[i].BrickColor = bcl;
end;
end;
end;

Unless script.Parent is going to change a lot, cache it. Unless the BrickColor is going to change a lot, cache it. Pairs runs in about 3x as much time as a standard for loop. You don't need to check if it's not the script if you're also checking if it is a BasePart.

0
its not "V" its "C" simple error, thanks! UltraUnitMode 419 — 8y
0
Thanks for catching that one. User#6546 35 — 8y
Ad
Log in to vote
0
Answered by 8 years ago

No, it cannot be faster unless you're looking for a certain name:

Local find = game.Workspace: FindFirstChild("ColorPart",true)

If find then
 --code
End

FindFirstChild has two parameters: 1. what you want to find 2. search through all descendants (default at false )

0
Oh okay.Thanks though UltraUnitMode 419 — 8y

Answer this question