Issues with Magnitude

I’ve tried in both Local and Server-side to make a script that when the player gets nearby a part, a Light would get enabled, unfortunately, it does absolutely nothing, and still, in the output, it gives no absolute error about it. I can’t even find a thing explaining it for good inside https://developer.roblox.com/.
Reference script:

local plr = game.Players.LocalPlayer
local char = plr.Character
local upper_Torso = char:WaitForChild("UpperTorso")

local min_distance_to_appear = 20

while wait() do
	if (upper_Torso.Position - script.Parent.Parent.Position).magnitude < min_distance_to_appear then
		script.Parent.Enabled = true
	else
		script.Parent.Enabled = false
	end
end

In this case, I used locally because I would like only said player who’s nearby the part to be able to see the light.

If it’s a local script, the code will only run if it’s a descendant of the character or if it’s a descendant of player. (Meaning startingGui and StarterPlayerScripts as well).

Im assuming based on the script that this is a descendant of workspace. To make it work you will have to reference the part a different way and reparent the script.

Would it be possible to make it for multiple lights with only one script?

It would probably be easiest to make a folder called Lights that has all of the parts with a light in it and put this script in StarterCharacterScripts.

So the hierarchy will look like this

Workspace
—Lights
——BasePart
———Light
——BasePart
———Light

You can name the BasePart whatever you want, but the rest has to be named as they are above for the way this one is written.

local upper_Torso = script.Parent:WaitForChild("UpperTorso")

local min_distance_to_appear = 20

while wait() do
  for i,light in pairs(game.Workspace.Lights:GetChildren()) do
    if light:FindFirstChild(“Light”) then
        light.Light.Enabled = (upper_Torso.Position - light.Position).magnitude < min_distance_to_appear --Does the same as your if statement
    end
  end
end

There are other ways of course, but this one is the easiest for me to explain quickly.

Aight, thank you, it should work perfectly.