I've searched all over the internet for a follow player only script, but they either don't work or are outdated. The NPCs attack each other not players (they're ignored) Any help is much appreciated (Please also explain the script to me, as i'm a total newbie at Lua scripting) This is my current follow 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 = 1000
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("Right Arm")
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
return torso
end
while true do
wait(math.random(1,5))
local target = findNearestTorso(script.Parent.Torso.Position)
if target ~= nil then
script.Parent.Humanoid:MoveTo(target.Position, target)
end
end
I wonder if my damage script does any difference to the NPCs actions but i'll put it here anyways :-
local rarm = script.Parent:FindFirstChild("Right Arm")
local larm = script.Parent:FindFirstChild("Left Arm")
function dmg(hit)
if hit.Parent ~= nil then
local hum = hit.Parent:findFirstChild("Humanoid")
if hum ~= nil then
hum.Health = hum.Health -10
end
end
end
rarm.Touched:connect(dmg)
larm.Touched:connect(dmg)

10 comments
Is your game using R15? If so, this could be the cause, because in your findNearestTorso you check for "Right Arm" which isn't present in R15, but rather "RightLowerArm" and "RightUpperArm"
The script you use is outdated, filled with deprecated code. It will for sure break your game.
I know it’s not your script, and ScriptingHelpers.org is a site for helping users with self written code, not code from free models.
@Kiriot22, how do i check if game used r15. Also would that make it LeftUpperArm and LeftLowerArm too or something? and thx for replying
And @incapaz, im sorry but i have no clue when scripting with Lua, and using free models scripts are my only choice at the moment for my game, but i do plan on learning Lua during summer break (properly). But thx for advice.
oh yeah... kiriot is right. I totally forgot that... it would also explain why if I test a game, in my character it says uper and lower arm instead of just, right arm. But I do think that it will still chase anyone tho.
And guys i've still not found an answer, even though i've been researching practically 2 hrs a day about lua and the question :((
":connect" is deprecated and ":findFirstChild" is too and your game should be r15
How do i change those words then? and i am pretty sure my game is r15 @mudathir2007 . Also guys the script in action is like the NPCs in the game Ro-Ghoul on Roblox, so if u want an idea on what I'm asking of u guys.
:connect is :Connect and findFirstChild is FindFirstChild