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

How do you make all parts do this at the same time?

There's a lot of parts in this model and i want them all to do the transparency loops at the same time, but it seems to be only doing it 1 at a time?

for i,v in pairs(workspace.Model:GetDescendants()) do
		if v:IsA('BasePart') or v:IsA('Decal') then
			for i =1,10 do
			local num =0
			repeat wait()
				num = num + 1
			v.Transparency = v.Transparency + 0.1
			until num == 9
			local num =0
			repeat wait()
				num = num + 1
			v.Transparency = v.Transparency - 0.1
			until num == 9
			end
				v.Transparency = 1
		end
	end
end

2 comments

0

Would it mess up your build to make the parts a single union?

0

if v.ClassName == "Part" then

3 answers

✓ Accepted answer

(for i, v in pairs) -- this means that in pairs, it will transparent two at a time.

Use a different method like for list = 1, # do ..

local ModelContents = {workspace.Model:GetChildren()}

for MC = 1, #ModelContents do 
	if ModelContents[MC]:IsA('BasePart') or ModelContents[MC]:IsA('Decal') then 
		ModelContents[MC].Transparency = 0.5
		-- code 
	end
end
-- Example
part1 = script.Parent.p1
part2 = script.Parent.p2
part3 = script.Parent.p3
while true do
	for i = 1,10 do
		part1.Transparency = part1.Transparency + 0.1
		part2.Transparency = part2.Transparency + 0.1
		part3.Transparency = part3.Transparency + 0.1
		wait(1)
	end
	for i = 1,10 do
		part1.Transparency = part1.Transparency - 0.1
		part2.Transparency = part2.Transparency - 0.1
		part3.Transparency = part3.Transparency - 0.1
		wait(1)
	end
end

3 comments

0

ya but the thing is theres like 100s of parts soo that would take forever

0

That would be the way to do that. You could also pass a list of parts to the loop.

0

Roblox Lua isn't that easy, you know.

Use a function called spawn() to run the code in a new thread.

for i,v in pairs(workspace.Model:GetDescendants()) do
	if v:IsA('BasePart') or v:IsA('Decal') then
		spawn(function()
			for i =1,10 do
				local num =0
				repeat wait()
					num = num + 1
					v.Transparency = v.Transparency + 0.1
				until num == 9
				local num =0
				repeat wait()
					num = num + 1
					v.Transparency = v.Transparency - 0.1
				until num == 9
			end
			v.Transparency = 1
		end)
	end
end

1 comment

0

cool pls help me now

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