Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
0

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

Asked by 4 years ago

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
    return torso
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 534 — 4y
0
the npcs are R15 Creeperbob16 28 — 4y

1 answer

Log in to vote
0
Answered by
panvvan 20
4 years ago

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
    return torso
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 28 — 4y
Ad

Answer this question