Still have questions? Join our Discord server and get real time help.
0

# How do I get rid of the "Left hand is not a valid member of model" error?

I have this script which is supposed to make an AI move towards the player. This script works if you replace anything that says LeftHand with HumanoidRootPart. I had to change the script as there were multiple AI causing them to attack each other instead of the player. I deleted the left hand of the AI as it doesn't change the look of the AI and thought I could just have them track down the left hand since none of the AI have a left hand, however this doesn't work. I simply get a "Left hand is not a valid member of model" error. What can I do to fix this?

local larm = script.Parent:FindFirstChild("LeftHand")
local rarm = script.Parent:FindFirstChild("LeftHand")

function findNearestTorso(pos)
local list = game.Workspace:children()
local torso = nil
local dist = 10000
local temp = nil
local human = nil
local temp2 = nil
for x = 1, #list do
temp2 = list[x]
if (temp2.className == "Model") and (temp2 ~= script.Parent) then
temp = temp2:findFirstChild("LeftHand")
human = temp2:findFirstChild("Humanoid")
if (temp ~= nil) and (human ~= nil) and (human.Health > 0) then
if (temp.Position - pos).magnitude < dist then
torso = temp
dist = (temp.Position - pos).magnitude
end
end
end
end

while true do
wait(math.random(1,5))
local target = findNearestTorso(script.Parent.LeftHand.Position)
if target ~= nil then
script.Parent.Humanoid:MoveTo(target.Position, target)
end

end


0
Are the NPCs R15 or R6? On R6, the left hand is called "Left Arm," and on R15 it is as you stated, "LeftHand". Sparks 484 — 7d
0
the npcs are R15 Creeperbob16 16 — 7d

0

First in many places you have written findFirstChild instead of FindFirstChild and second becoz its R15 u need to specify the upper or lower arm, hand etc and (this is an asumption but u need to change rarm to righthand)

local larm = script.Parent:FindFirstChild("LeftHand")
local rarm = script.Parent:FindFirstChild("LeftHand")

function findNearestTorso(pos)
local list = game.Workspace:children()
local torso = nil
local dist = 10000
local temp = nil
local human = nil
local temp2 = nil
for x = 1, #list do
temp2 = list[x]
if (temp2.className == "Model") and (temp2 ~= script.Parent) then
temp = temp2:FindFirstChild("LeftHand")
human = temp2:FindFirstChild("Humanoid")
if (temp ~= nil) and (human ~= nil) and (human.Health > 0) then
if (temp.Position - pos).magnitude < dist then
torso = temp
dist = (temp.Position - pos).magnitude
end
end
end
end

while true do
wait(math.random(1,5))
local target = FindNearestTorso(script.Parent.LeftHand.Position)
if target ~= nil then
script.Parent.Humanoid:MoveTo(target.Position, target)
end

end


0
it still comes up with the same error :/ Creeperbob16 16 — 7d