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

Torso is not a valid member of Model "Workspace.SCP-087-D" server script?

Asked by 1 year ago

local larm = script.Parent:FindFirstChild("Left Arm") local rarm = script.Parent:FindFirstChild("Right Arm")

function findNearestTorso(pos) local list = game.Workspace:children() local torso = nil local dist = 30 --This Line Right Here 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("Torso") human = temp2:findFirstChild("Humanoid") Friend = temp2:findFirstChild("Friend") if (temp ~= nil) and (human ~= nil) and (human.Health > 0) and (Friend == nil) or (temp ~= nil) and (human ~= nil) and (human.Health > 0) and (Friend.Value ~= script.Parent.Friend.Value) then if (temp.Position - pos).magnitude < dist then torso = temp dist = (temp.Position - pos).magnitude end end end end return torso end

while true do wait(0.1) local target = findNearestTorso(script.Parent.Torso.Position) if target ~= nil then script.Parent.SCP:MoveTo(target.Position, target) end end

1 answer

Log in to vote
0
Answered by 1 year ago

It's probably because the SCP is R15. Also next time, fix your answer, you should always put your code inside a code block by pressing the Lua icon. And provide some details on what you're trying to do and explain why you're doing this.

The solution is using script.Parent.HumanoidRootPart instead of script.Parent.Torso.

local monster = script.Parent
local monsterTorso = monster:FindFirstChild("Torso") or monster:FindFirstChild("HumanoidRootPart")

function findNearestTorso(pos)
    local list = game.Workspace:GetDescendants()
    local torso = nil
    local dist = 30 --This Line Right Here

    for _, descendant in ipairs(list) do
        if descendant:IsA("Model") and descendant ~= monster then
            local temp = descendant:FindFirstChild("Torso") or descendant:FindFirstChild("HumanoidRootPart")
            local human = descendant:FindFirstChildOfClass("Humanoid")
            local Friend = descendant:FindFirstChild("Friend")
            if (temp ~= nil) and (human ~= nil) and (human.Health > 0) then
                if Friend ~= nil then
                    if Friend:IsA(monster.Friend.ClassName) then
                        if Friend.Value ~= monster.Friend.Value then
                            if (temp.Position - pos).Magnitude < dist then
                                torso = temp
                                dist = (temp.Position - pos).Magnitude
                            end
                        end
                    end
                else
                    if (temp.Position - pos).Magnitude < dist then
                        torso = temp
                        dist = (temp.Position - pos).Magnitude
                    end
                end
            end
        end
    end

    return torso
end

while true do
    task.wait(0.1)

    local target = findNearestTorso(monsterTorso.Position)
    if target ~= nil then
        script.Parent.SCP:MoveTo(target.Position, target)
    end
end
0
No it is the SCP that is R6 just the script is old from 2017 so I see why it is broken due to age WindowsVistaiswow 4 — 1y
0
Try using `monster:WaitForChild("Torso")` in my script T3_MasterGamer 2189 — 1y
0
It works WindowsVistaiswow 4 — 1y
Ad

Answer this question