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

Why is only one decal being affected when I need all of them to be?

This has been a struggle for me for quite some time. Basically, I'm trying to make an animated camo and I'm trying to use a for i,v in pairs loop to get all of the decals within the weapon. However it does work kinda, it only affects the top decal, I'm sure why...

Any help will be appreciated :D

for i,v in pairs(workspace.Part:GetChildren()) do
	
	if v:IsA("Decal") then
		
		for _, test in pairs(workspace.Part2:GetChildren()) do
			
			if test:IsA("Decal") then
				
				if v.Name == test.Name then
				
				while run.RenderStepped:Wait() do
					
					test.Texture = v.Texture
					
					end
					
				end
				
			end
			
		end
		
	end
	
end

1 answer

✓ Accepted answer

Ah. Once your script gets to the while loop, it doesn't exit the loop, so it appears that only that one works because your script doesn't really create a loop for the other ones. It doesn't finish the execution of that iteration of the for loop, because it entered a never ending while loop.

A simple way to get around this would be to just connect a function to RenderStepped(), instead of creating a loop, like:

RenderStepped:Connect(function(delta)
	test.Texture = v.Texture
end

This way, it doesn't get stuck in an endless loop, and can continue looping through the other decals.

Really, though, this question has to do with running multiple uhhhh "threads" in "parallel", like switching decals in loops inside only one script. Technically not "true parallel" but practically speaking, it kinda does anyway, and getting too technical about things isn't really what I like to do, I just want to get things done then go deeper if I have to. Read here if you'd like to learn more.

Hope that helps!

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