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

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

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

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)

2 comments

0

So all bricks invisible for five seconds? Just use two for loops, have the five second wait between them.

0

Fixed indentation.

1 answer

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

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

1 comment

0

Thank you so much.

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