Attempt to index nil with position

A script within a model keeps repeating index wil with position even though the part is defined.
The error occurs on the last line of the script, It is a serverscript.

local Sound = "Slash"
local Debris = game:GetService("Debris")
local SmallestMagnitude = 40
local NewTHRP = nil
local tool = script.Parent
repeat task.wait() until script.Parent
local targetfound = false
repeat task.wait() until script.Parent.Name ~= "UndyneAttacks"
local mag = 4000
local player = game.Players:GetPlayerFromCharacter(script.Parent.Parent)
local tar = nil

local players = game.Players:GetChildren()
local range = 400
local lastmag= 1000
local mHum = script.Parent:FindFirstChild("Boss")
for i=1,#players do
	task.wait()
	if players[i].Character then
		local char = players[i].Character
		if char:FindFirstChild("Torso") then
			local Torso = char:FindFirstChild("Torso")
			if mag<=range then
				if char.Name ~= script.Parent.Name then
						lastmag = mag
						TargetCFrame = CFrame.new(Torso.CFrame.x,Torso.CFrame.y,Torso.CFrame.z)
						TargetPosition = Vector3.new(Torso.Position.x,Torso.Position.y,Torso.Position.z)
						targetfound = true
						tar = Torso
					end
				end
			end
		end
	end
						local Spear = script.Parent
						Spear.HumanoidRootPart.CFrame = CFrame.lookAt(Spear.HumanoidRootPart.Position,tar.Position)

Help would be appreciated thank you.

Either tar was not found or Spear.HumanoidRootPart does not exist. Try printing out targetFound to see if tar was found

This means that tar stayed as nil