Advertisement
Guest User

NPC Follow

a guest
Mar 22nd, 2016
17,597
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 0.86 KB | None | 0 0
  1. players = nil; --Where we are going to store all the players
  2. dummy = game.Workspace.Dummy; --Dummy reference
  3. currentPlayerFollowing = nil; --The current player the zombie is following
  4.  
  5. while wait(1) do --Forever loop
  6.  players = game.Players:GetChildren(); --Grab all the Players currently in the game
  7.  
  8.  for i = 0, table.getn(players), 1 do --Go through all of the players
  9.   if (players[i] ~= nil and (math.abs(players[i].Character.Torso.Position.X - dummy.Torso.Position.X)) <= 10) then --Subtract the distance between the player and the zombie
  10.    currentPlayerFollowing = players[i]; --Add the player to the currentPlayerFollowing reference so the zombie can follow them
  11.   end
  12.  end
  13.  
  14.  if (currentPlayerFollowing ~= nil) then --If the player is there
  15.     dummy.Humanoid.WalkToPoint = currentPlayerFollowing.Character.Torso.Position --Walk to the player
  16.  end
  17. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement