Advertisement
Tacidus

Wandering NPC

Jul 22nd, 2020
137
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 1.09 KB | None | 0 0
  1. local CurrentPart = nil
  2. local MaxInc = 60
  3.  
  4. function onTouched(hit)
  5.     if hit.Parent == nil then
  6.         return
  7.     end
  8.  
  9.     local humanoid = hit.Parent:findFirstChild("Humanoid")
  10.  
  11.     if humanoid == nil then
  12.         CurrentPart = hit
  13.     end
  14. end
  15.  
  16. function waitForChild(parent, childName)
  17.     local child = parent:findFirstChild(childName)
  18.  
  19.     if child then
  20.         return child
  21.     end
  22.  
  23.     while true do
  24.         print(childName)
  25.  
  26.         child = parent.ChildAdded:wait()
  27.  
  28.         if child.Name==childName then
  29.             return child
  30.         end
  31.     end
  32. end
  33.  
  34. local Figure = script.Parent
  35. local Humanoid = waitForChild(Figure, "Humanoid")
  36. local Torso = waitForChild(Figure, "HumanoidRootPart")
  37. local Left = waitForChild(Figure, "LeftFoot")
  38. local Right = waitForChild(Figure, "RightFoot")
  39.  
  40. Humanoid.Jump = true
  41.  
  42. Left.Touched:connect(onTouched)
  43. Right.Touched:connect(onTouched)
  44.  
  45. while true do
  46.     wait(math.random(2, 6))
  47.  
  48.     if CurrentPart ~= nil then
  49.         if math.random(5, 7) == 1 then
  50.             Humanoid.Jump = true
  51.         end
  52.  
  53.         Humanoid:MoveTo(Torso.Position + Vector3.new(math.random(-MaxInc, MaxInc), 0, math.random(-MaxInc, MaxInc)), CurrentPart)
  54.     end
  55. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement