Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
✓ ANSWER ACCEPTED

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

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

✓ Accepted answer

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

3 comments

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

0

Try using monster:WaitForChild("Torso") in my script

0

It works

This discussion is preserved as it was. New answers, comments, and votes are closed.