So I've been working on my game and I've got a script that shows a GUI when I come in 10 studs radius of the NPC or as I named it: "Dummy". The Dummies are located in a special folder called "Dummys" in the workspace. I have been recently working on the "Magnitude" function. I am fairly new to scripting and I am still learning. For the scripts, I want to do I normally get stuck on them for hours upon hours, and I have to watch a lot of videos in order to fix certain sections of the scripts. The local script's location is in a Gui and that Gui is located in StarterGui.
The error message says:
Players.Himillumine.PlayerGui.Every.Checker:16: bad argument #1 to '?' (Vector3 expected, got nil)
This is the script:
local Players = game:GetService("Players")
local player = Players.LocalPlayer
local myTorso = player.Character:GetChildren("Torso")
local myHumanoid = player.Character:FindFirstChild("Humanoid")
function findTarget()
local dist = Vector3.new(10, 10, 10)
local target = nil
for i,v in pairs(game.Workspace.Dummys:GetChildren()) do
if v.Name == "Dummy" then
local human = v:FindFirstChild("Humanoid")
local torso = v:FindFirstChild("Torso")
if human and torso then
if human.Health > 0 then
if (myTorso.Position - torso.Position).Magnitude < dist then
dist = (myTorso.Position - torso.Position).Magnitude
target = torso
print("Works!")
end
end
end
end
end
return target
end
while wait(1) do
local torso = findTarget()
if torso then
script.Parent.Enabled = true
print("YES!")
else
print("NOO!")
end
end

2 comments
player.Character:GetChildren("Torso") isn't a thing. Depending upon when this script runs, you may need WaitForChild() in place of some of your FindFirstChild() calls. Also, for getting the Humanoid, it's preferable to use FindFirstChildOfClass("Humanoid").
Thank you so much I appreciate it.