This is what i have working for so far
sript.Parent.Touched:Connect(function(hit)
local hitd = {}
local Tower = script.Parent.Tower.Position
local HumanoidRootPart = hit.Parent:FindFirstChild("HumanoidRootPart").Position
hitd[#hitd+1] = HumanoidRootPart
local TargetDistance = math.huge
local Target
for i,v in ipairs(hitd) do
if v == HumanoidRootPart then
Target = v
local TargetHRP = HumanoidRootPart
local mag = (Tower - Target).Magnitude
if mag < TargetDistance then
TargetDistance = mag
Target = v
end
return Target
end
end
end)
if it not able what about this?
local function FOUNDTARGET(hit)
local hitd = {}
local Tower = script.Parent.Tower.Position
local HumanoidRootPart =
hit.Parent:FindFirstChild("HumanoidRootPart").Position
hitd[#hitd+1] = HumanoidRootPart
local TargetDistance = math.huge
local Target
for i,v in ipairs(hitd) do
if v == HumanoidRootPart then
Target = v
local TargetHRP = HumanoidRootPart
local mag = (Tower - Target).Magnitude
if mag < TargetDistance then
TargetDistance = mag
Target = v
end
return Target
end
end
end
script.Parent.Touched:Connect(FOUNDTARGET)
local Target = FOUNDTARGET()
print(Target)
For now my expected output is just want to see they print Position
