Looping magnitude is only working for one part in the folder?

You can write your topic however you want, but you need to answer these questions:

  1. **I want it to work for all parts in the folder

  2. **It works for one part, and none of the others

  3. **I have tried two different methods ill post below

fogparts = {} -- do not mess with this this will be the amount of parts touched to turn on fog
for i,v in pairs(game.Workspace.FogParts:GetChildren()) do
        table.insert(fogparts,v)
end

plyr = game.Players.LocalPlayer

tdn = false -- do not mess with this 
repeat wait() until plyr.Character --- dont mess with this or anything aboce
    
char = plyr.Character -- dont mess with this
hr = char:WaitForChild("HumanoidRootPart") -- dont mess with this

print("yes")
lighting = game:GetService("Lighting") --- dont mess with this
atmos = lighting:WaitForChild("Atmosphere") -- dont mess with this
--Stuff you can change below -- 

print("getting")
origdens = atmos.Density
orighaze = atmos.Haze

origglare = atmos.Glare
origName = atmos.Name


newdens = 0.5
newhaze = 9
newglare = atmos.Glare
newName = atmos.Name

while wait() do
   
    for i,v in pairs(fogparts) do

        if (v.Size.Z / 2) >= (hr.Position - v.Position).Magnitude or (v.Size.X / 2) >= (hr.Position - v.Position).Magnitude or (v.Size.Y / 2) >= (hr.Position - v.Position).Magnitude then
                        atmos.Color = Color3.fromRGB(124, 170, 113)
                atmos.Decay = Color3.fromRGB(181, 214, 16)
            atmos.Density = newdens
    atmos.Glare = newglare
    atmos.Haze = newhaze
            atmos.Name = newName
            print("fog")
                else 
            print("nofog")
                     atmos.Color = Color3.fromRGB(199, 170, 107)
    atmos.Decay = Color3.fromRGB(92, 60, 13)
            atmos.Density = origdens
    atmos.Glare = origglare
            atmos.Name = origName 
            atmos.Haze = orighaze 
        end
    end
end
  
fogparts = {} -- do not mess with this this will be the amount of parts touched to turn on fog
for i,v in pairs(game.Workspace.FogParts:GetChildren()) do
        table.insert(fogparts,v)
end

plyr = game.Players.LocalPlayer

tdn = false -- do not mess with this 
repeat wait() until plyr.Character --- dont mess with this or anything aboce
    
char = plyr.Character -- dont mess with this
hr = char:WaitForChild("HumanoidRootPart") -- dont mess with this

print("yes")
lighting = game:GetService("Lighting") --- dont mess with this
atmos = lighting:WaitForChild("Atmosphere") -- dont mess with this
--Stuff you can change below -- 

print("getting")
origdens = atmos.Density
orighaze = atmos.Haze

origglare = atmos.Glare
origName = atmos.Name


newdens = 0.5
newhaze = 9
newglare = atmos.Glare
newName = atmos.Name
for i=1,#fogparts do
print(fogparts[i])
end
for i=1,#fogparts do
   function CheckMag(v)
wait()
   while wait() do
        if (v.Size.Z / 2) >= (hr.Position - v.Position).Magnitude or (v.Size.X / 2) >= (hr.Position - v.Position).Magnitude or (v.Size.Y / 2) >= (hr.Position - v.Position).Magnitude then
			           
				 atmos.Color = Color3.fromRGB(124, 170, 113)
				atmos.Decay = Color3.fromRGB(181, 214, 16)
			atmos.Density = newdens
	atmos.Glare = newglare
	atmos.Haze = newhaze
			atmos.Name = newName
			print("fog")
		        else 
			
			
			
                     atmos.Color = Color3.fromRGB(199, 170, 107)
	atmos.Decay = Color3.fromRGB(92, 60, 13)
			atmos.Density = origdens
	atmos.Glare = origglare
			atmos.Name = origName 
			atmos.Haze = orighaze 
        end
    end
	end
CheckMag(fogparts[i])
end


    
    ```

Please do not ask people to write entire scripts or design entire systems for you. If you can't answer the three questions above, you should probably pick a different category.

First thing I noticed is that you put the parts from the folder instantly into a table. Don’t do that because it’s possible that some parts dindt load in yet, so inside the for loop, just do folder:GetChildren() it should fix your problem.

Here’s how it should look like if you didn’t understand that.

plyr = game.Players.LocalPlayer

tdn = false -- do not mess with this 
repeat wait() until plyr.Character --- dont mess with this or anything aboce
    
char = plyr.Character -- dont mess with this
hr = char:WaitForChild("HumanoidRootPart") -- dont mess with this

print("yes")
lighting = game:GetService("Lighting") --- dont mess with this
atmos = lighting:WaitForChild("Atmosphere") -- dont mess with this
--Stuff you can change below -- 

print("getting")
origdens = atmos.Density
orighaze = atmos.Haze

origglare = atmos.Glare
origName = atmos.Name


newdens = 0.5
newhaze = 9
newglare = atmos.Glare
newName = atmos.Name
for i,v in pairs(workspace.FogParts:GetChildren()) do
   print(v)
   function CheckMag(v)
wait()
   while wait() do
        if (v.Size.Z / 2) >= (hr.Position - v.Position).Magnitude or (v.Size.X / 2) >= (hr.Position - v.Position).Magnitude or (v.Size.Y / 2) >= (hr.Position - v.Position).Magnitude then
			           
				 atmos.Color = Color3.fromRGB(124, 170, 113)
				atmos.Decay = Color3.fromRGB(181, 214, 16)
			atmos.Density = newdens
	atmos.Glare = newglare
	atmos.Haze = newhaze
			atmos.Name = newName
			print("fog")
		        else 
			
			
			
                     atmos.Color = Color3.fromRGB(199, 170, 107)
	atmos.Decay = Color3.fromRGB(92, 60, 13)
			atmos.Density = origdens
	atmos.Glare = origglare
			atmos.Name = origName 
			atmos.Haze = orighaze 
        end
    end
	end
CheckMag(v)
end```

now it prints fog and nofog, in both parts, but only works for one

I edited the previous post to include how the script should look like

that one also only works for one
ill provide you with a gyazo of whats happening

so this is whats happening as you can see one part works as its supposed to, the other does not do anything at all
https://gyazo.com/3f261296518806f9bec0877b3fee21c4

any ideas? that was your version copied/pasted and a problem with the ends fixed

try adding this at the very beginning of the script

if not game:IsLoaded() then game.Loaded:Wait() end

Still only working for one :confused:

I fixed it, i had to account for the closest part for it to even work almost as if i was doing a follow script for a humanoid, but it worked

Hi!

I know this is quite an old thread, but I spotted it by chance and it seemed appropriate to post an explanation here for anyone reading this in the future, since I ran into similar topic today.

Check this post out: