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

How do i make the npc follow me when i reach a certain distance?

Asked by 6 years ago
Edited 6 years ago

--note this is a script inside the model It does not work in the actual game just in studio I tried making it a localscript didn't work

local distance = 500
players = nil; --Where we are going to store all the players
dummy = game.Workspace.Berserker; --Dummy reference
currentPlayerFollowing = nil; --The current player the zombie is following

while wait(1) do --Forever loop
 players = game.Players:GetChildren(); --Grab all the Players currently in the game

 for i = 0, table.getn(players), 1 do --Go through all of the players
  if (players[i] ~= nil and (math.abs(players[i].Character.UpperTorso.Position.X - dummy.UpperTorso.Position.X)) <= 10) then --Subtract the distance between the player and the zombie
   currentPlayerFollowing = players[i]; --Add the player to the currentPlayerFollowing reference so the zombie can follow them
  end

 if (currentPlayerFollowing ~= nil) then --If the player is there
    dummy.Humanoid.WalkToPoint = currentPlayerFollowing.Character.UpperTorso.Position --Walk to the player
 end
end
end
0
Please use code block then I can answer. MicrosoftS98 17 — 6y
0
Werid.. i couldve sworn i did PlacevRebuilder -5 — 6y

Answer this question