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

How to make all parts in a model transparent at once?

Hello. So I'm trying to make a script that would make all the parts in a model visible for a quick second and then repeat after another 5 seconds (using GetChildren so I wouldn't have to address every single part with a line of code). The problem is that when the script runs, It only makes one part visible at a time. Is there a way I could make it so that all the parts inside the model do the same thing at the same time? Any help would be greatly appreciated.

local gold = game.Workspace.gold
	for i, v in pairs(gold:GetChildren()) do
	if v:IsA("Part") then
	wait(1)
	v.Transparency = 0
	v.CanCollide = true
	wait(5)
	v.Transparency = 1		
	v.CanCollide = false			
		end
	end

1 comment

0

Hi! For this case, you should use something called "coroutine". It's extremely useful for running multiple things at once. See https://developer.roblox.com/en-us/api-reference/lua-docs/coroutine for more information

2 answers

Take it out of a While loop. Once the pairs loop goes through once, it seems like its just repeating in the while loop again, instead of continuing the pairs loop.

1 comment

0

I did but it still does only one part at a time

put whats inside your loop in a coroutine

A coroutine is used to perform multiple tasks at the same time from within the same script.

example

local gold = workspace.gold
for i, v in pairs(gold:GetChildren()) do
	coroutine.wrap(function() 
	 	if v:IsA("Part") then
			wait(1)
			v.Transparency = 0
			v.CanCollide = true
			wait(5)
			v.Transparency = 1      
			v.CanCollide = false            
	 	end	
	end)()
end

6 comments

0

Good idea. Converting my comment into an answer

0

i posted my anwser before i even saw your comment, check the time between them. i posted 6min after yours thats not enough time  for me to post this, since i had to verify that this code indeed works  and doesnt error

0

It does make them invisible at the same time but they dont become visible again :/

0

yeah because thats what the code you gave me does, transperancy = 0 is visible, Transparency = 1 is invisible also make sure you part is anchored or else it will fall into the void and get destroyed when you set cancollide false

0

yeah but I meant for it to loop over and over again

0

then add a loop around this loop

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