For Loop Not Running All The Way?

I don’t know why but this for loop stops at some point and doesn’t make some parts change.

this is a local script btw in starter player scripts

task.wait(1)

local NVParts = game.Workspace.NightVisionParts


local function Trans()
for i, v in NVParts:GetChildren() do
	if v.Transparency == 1 then
		for _, t in v:GetChildren() do
			t.Transparency = .8
			end
		end
	end
end

while true do
	Trans()
	task.wait(0.5)
end

I just tried tweaking the script and this is what I got, works fine in studio but not in roblox.

task.wait(3)

local NVParts = game.Workspace.NightVisionParts


local function Trans()
for i, v in NVParts:GetChildren() do
	if v.Transparency == 1 then
		for _, t in v:GetChildren() do
			t.Transparency = .8
		
			end
		end
end
	wait(.01)
end

while true do
	Trans()
	task.wait(1)
end

Just to check something - if you turn off Streaming Enabled, does it fix the issue?

Where would you find streaming enabled?

I believe it’s a property of workspace, near the bottom of the properties.

It Worked! Thanks a lot. (would you know what that setting does by chance?)

My reply wasn’t meant to be the solution itself - You will probably want to turn streaming back on. Basically, Streaming Enabled means that the objects in the game are unloaded if the player is too far away from them, and loaded when it is close to the player. The reason it was causing issues for you is that it is unloading things which you want loaded.

A simple fix would be to turn streaming enabled back on and, assuming NVParts is a model, set the streaming behaviour of it to Atomic (which means everything in it is either loaded or unloaded together.)

NVParts is a folder, should i just switch it to a model then?

(Worked Though! Thanks!)

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.