ClosestRoot Does not reset after death

I am programming a 173 system where if a player doesn’t look then the scp kills you. But I search for the closest root part. to do so I do this:

			if ClosestRoot == nil then 
				if not Player:GetAttribute("Looking") then
					ClosestRoot = HumanoidRootPart
				end
			else
				if (ClosestRoot.Position - Rig.HumanoidRootPart.Position).Magnitude > (HumanoidRootPart.Position - Rig.HumanoidRootPart.Position).Magnitude then
					if Player:GetAttribute("Looking") == false then
						ClosestRoot = HumanoidRootPart
					end
				end
			end

This check is in a player added loop.

The detection works fine as I debugged it and nothing seems to be off, but when I print the root position it doesn’t use the new root and still thinks that the old root still is there. this is the code the decides what to do:

	if #LookingPlayers == 0 and ClosestRoot ~= nil then
		Path:Run(ClosestRoot.Parent.HumanoidRootPart.Position)
		Roaming = false
	elseif  #LookingPlayers == 0 and ClosestRoot == nil then
		if not Roaming then
			Roaming = true
			Path:Run(Vector3.new(Rig.HumanoidRootPart.Position.X + math.random(-15, 15), Rig.HumanoidRootPart.Position.Y), Rig.HumanoidRootPart.Position.Z + math.random(-15, 15))
			TimeTillNextRoam = tick() + math.random(0, 15)
		else
			if TimeTillNextRoam <= tick() then
				Path:Run(Vector3.new(Rig.HumanoidRootPart.Position.X + math.random(-15, 15), Rig.HumanoidRootPart.Position.Y), Rig.HumanoidRootPart.Position.Z + math.random(-15, 15))
				TimeTillNextRoam = tick() + math.random(0, 15)
			end
		end
	end

I use simple path to find the path but that does not cause the problem. It’s that the ClosestRoot is always the same old one even when the player already died. There are no errors.

I tried using character but that had the same bug