Hello, im a new guy here and this is my first post here and i have a question,i followed TheDevKing's Magnitude script tutorial and when i finished the script,i tried to test it but it said Workspace.magnitudescript:23: attempt to perform arithmetic(sub) on nil and Vector3
Heres the script
local zombieTorso = script.Parent.HumanoidRootPart
local zombieHumanoid = script.Parent.Humanoid
local function findTarget()
local agroDistance = 100
local hitDistance = 6
local target = nil
for _, v in pairs(game.Workspace:GetChildren()) do
local human = v:FindFirstChild("Humanoid")
local torso = v:FindFirstChild("HumanoidRootPart")
local npc = v:FindFirstChild("ZombieNPC")
if human and torso and v ~= npc then
if (zombieTorso.Position - torso.Position).magnitude < agroDistance then
agroDistance = (zombieTorso.Position - torso.Position).magnitude
target = torso
if (zombieTorso.Position - torso.Position).magnitude <= hitDistance then
human.Health = human.Health - 10
end
end
end
end
return target
end
while wait(1) do
local torso = findTarget()
if torso then
zombieHumanoid:MoveTo(torso.Position)
else
zombieHumanoid:MoveTo(zombieTorso.Position + Vector3.new(math.random(-50, 50), 0, math.random(-50, 50)))
end
end
I`m sorry if you didnt understand well the question, english is not my primary language(also you can tell about any other mistakes i did,i wanted to also make that the target will take damage)

1 comment
Thanks alot! This worked, i will come here if i have any more issues