I’m trying to make this AI (SCP-106) come into the Pocket Dimension he sends you to and kill you if you don’t try to escape on your own. When he gets into the Pocket Dimension, he uses the same script to walk to you as he does at the beginning of the video.
For some reason, he flies around and off the map and then dies in the void instead of walking 2 feet to the person.
I’ve looked all over for a solution, but I just can’t figure it out.
-- code for the first part (that works)
local larm = script.Parent:FindFirstChild("HumanoidRootPart")
local rarm = script.Parent:FindFirstChild("HumanoidRootPart")
local scps = game.Workspace["SCP Entities"]
local 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("HumanoidRootPart")
human = temp2:findFirstChild("Humanoid")
if (temp ~= nil) and (human ~= nil) and (human.Health > 0) then
if (temp.Position - pos).magnitude < dist then
local pd = temp:FindFirstChild("PD")
if temp.Parent.Parent ~= scps then
if pd then
if pd.Value == false then
torso = temp
dist = (temp.Position - pos).magnitude
end
end
end
end
end
end
end
return torso
end
while mode.Value == 2 do
wait(1)
local target = findNearestTorso(script.Parent.HumanoidRootPart.Position)
if target ~= nil then
script.Parent.Humanoid:MoveTo(target.Position, target)
end
end
-- code for the second part of the video (Where he has a stroke)
local larm = script.Parent:FindFirstChild("HumanoidRootPart")
local rarm = script.Parent:FindFirstChild("HumanoidRootPart")
local scps = game.Workspace["SCP Entities"]
local 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("HumanoidRootPart")
human = temp2:findFirstChild("Humanoid")
if (temp ~= nil) and (human ~= nil) and (human.Health > 0) then
if (temp.Position - pos).magnitude < dist then
local pd = temp:FindFirstChild("PD")
if temp.Parent.Parent ~= scps then
if pd then
if pd.Value == true then
torso = temp
dist = (temp.Position - pos).magnitude
end
end
end
end
end
end
end
return torso
end
while mode.Value == 4 do
wait(1)
local target = findNearestTorso(script.Parent:FindFirstChild("HumanoidRootPart").Position)
if target ~= nil then
script.Parent.Humanoid:MoveTo(target.Position, target)
end
end
What happens and how do I fix it? Here’s the video:
https://medal.tv/games/roblox-studio/clips/7LzTGuymxenez/d1337ZqCC0rv?invite=cr-MSx3QTQsMzcwMjk5OTAs