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

[Solved]Table Problem Need Help Bad(should be Easy for most people)?

Asked by 5 years ago
Edited 5 years ago

my problem is that I'm making a Table of all the children in the Model Orb and what I want it to do is on touch of the Orb make the model go invis and 5 seconds later come make to visible. when the code is ran and then I touch the part it goes invis 1 part at a time every 5 seconds. I know its because its looping but is there anyway I can make a table that does not loop and still uses GetChildren. THANK YOU for reading

```lua local Orb = script.Parent:GetChildren()

function onTouched() for i, v in pairs(Orb) do v.Transparency = 1 wait(5) v.Transparency = 0 end end

script.Parent.Part.Touched:connect(onTouched) ```

0
So all bricks invisible for five seconds? Just use two for loops, have the five second wait between them. M39a9am3R 3210 — 5y
0
Fixed indentation. User#24403 69 — 5y

1 answer

Log in to vote
0
Answered by 5 years ago

A writeup of what M39a9am3R said

Your codes are waiting 5 seconds on the same part. A generic for loop generally traverses a table. i is the position of v in the array returned by instance:GetChildren().

When the code in the loop is complete it moves on to the next element. And it keeps going until the last element is reached.

What you can do is have two separate loops (like mentioned by M39a9am3R).

Something like this

```lua local orbs = script.Parent:GetChildren();

for _, orb in ipairs(orbs) do orb.Transparency = 1; end

wait(5); --// Wait 5 seconds before going to the next loop

for _, orb in ipairs(orbs) do orb.Transparency = 0; end ```

0
Thank you so much. TheMiner121 0 — 5y
Ad

Answer this question