Magnitude problems, trying to get when a person is inside of a part

I want to get anytime the player is inside of a part no matter what Size the part is.

The distance is off depending on the size, and it dose not work for every part in the table

If I make the part to big, it will register outside of the actual part, and it will only work at all for a single part even though im looping.

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 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
    
    

Also there are so many comments in this cause I am setting it up for a friend to use.

Are the Parts square? The script seems to only be reading the value for the Z dimension then dividing it by 2 and calculating it based on the Part’s Position. The problem with that is if you have a Part where the X dimension is longer, or you touch the corner of the Part (which is not half the distance of the Part’s Z dimension away from the Position of the Part) then the calculation isn’t trying to find the correct dimension.

I am not the best at math, how would I go about calculating the x,y,and z the correct way for it to register.
also any idea why its only working on one part even though its looping through the whole table?

Actually I checked x,y,and z the only issue now is its not doing it for every part in the folder

heres the updated code

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
    
    ```