Advertisement
Roblox-Studio

AlChase

Apr 23rd, 2019
102
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 6.51 KB | None | 0 0
  1. --[[
  2.  
  3. ____________________________________________________________________________________________________________________
  4.  
  5. =-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-
  6. ____________________________________________________________________________________________________________________
  7. ___ ___
  8. ( ) ( ) .-.
  9. .--. .--. | |_ | |_ ( __) ___ .-. .--. .--.
  10. / _ \ / \ ( __) ( __) (''") ( ) \ / \ / _ \
  11. . .' `. ; | .-. ; | | | | | | | .-. . ; ,-. ' . .' `. ;
  12. | ' | | | | | | | | ___ | | ___ | | | | | | | | | | | ' | |
  13. _\_`.(___) | |/ | | |( ) | |( ) | | | | | | | | | | _\_`.(___)
  14. ( ). '. | ' _.' | | | | | | | | | | | | | | | | | | ( ). '.
  15. | | `\ | | .'.-. | ' | | | ' | | | | | | | | | ' | | | | `\ |
  16. ; '._,' ' ' `-' / ' `-' ; ' `-' ; | | | | | | ' `-' | ; '._,' '
  17. '.___.' `.__.' `.__. `.__. (___) (___)(___) `.__. | '.___.'
  18. ( `-' ;
  19. `.__.
  20. ____________________________________________________________________________________________________________________
  21.  
  22. =-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-
  23. ____________________________________________________________________________________________________________________
  24.  
  25. --]]
  26.  
  27.  
  28. local SearchDistance = 150 -- How far a player can be before it detects you
  29.  
  30. local aiDamage = 20 -- How much damage the ai inficts towards the player
  31.  
  32. --[[
  33.  
  34. ____________________________________________________________________________________________________________________
  35.  
  36. =-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-
  37. ____________________________________________________________________________________________________________________
  38.  
  39. -- OPTIONAL --]]
  40.  
  41. local canWander = false
  42. local WanderX, WanderZ = 0, 0
  43. -- How many studs the ai can wander on the x and z axis in studs
  44.  
  45. --]]
  46.  
  47.  
  48. function getHumanoid(model)
  49. for _, v in pairs(model:GetChildren()) do
  50. if v:IsA'Humanoid' then
  51. return v
  52. end
  53. end
  54. end
  55.  
  56.  
  57. local ai = script.Parent
  58. local human = getHumanoid(ai)
  59. local hroot = ai.HumanoidRootPart
  60. local zspeed = hroot.Velocity.magnitude
  61.  
  62.  
  63. local pfs = game:GetService("PathfindingService")
  64.  
  65. function GetPlayerNames()
  66. local players = game:GetService('Players'):GetChildren()
  67. local name = nil
  68. for _, v in pairs(players) do
  69. if v:IsA'Player' then
  70. name = tostring(v.Name)
  71. end
  72. end
  73. return name
  74. end
  75.  
  76. spawn(function()
  77. while wait() do
  78. print("THIS BALDI MODEL WAS MADE BY ANPHU04, DO NOT TRUST ANYBODY THAT USES THIS!")
  79. end
  80. end)
  81.  
  82. function GetPlayersBodyParts(t)
  83. local torso = t
  84. if torso then
  85. local figure = torso.Parent
  86. for _, v in pairs(figure:GetChildren()) do
  87. if v:IsA'Part' then
  88. return v.Name
  89. end
  90. end
  91. else
  92. return "HumanoidRootPart"
  93. end
  94. end
  95.  
  96. function GetTorso(part)
  97. local chars = game.Workspace:GetChildren()
  98. local torso = nil
  99. for _, v in pairs(chars) do
  100. if v:IsA'Model' and v ~= script.Parent and v.Name == GetPlayerNames() then
  101. local charRoot = v:FindFirstChild'HumanoidRootPart'
  102. if (charRoot.Position - part).magnitude < SearchDistance then
  103. torso = charRoot
  104. end
  105. end
  106. end
  107. return torso
  108. end
  109.  
  110. for _, zambieparts in pairs(ai:GetChildren()) do
  111. if zambieparts:IsA'Part' then
  112. zambieparts.Touched:connect(function(p)
  113. if p.Parent.Name == GetPlayerNames() and p.Parent.Name ~= ai.Name then -- damage
  114. local enemy = p.Parent
  115. local enemyhuman = getHumanoid(enemy)
  116. enemyhuman:TakeDamage(aiDamage)
  117. end
  118. end)
  119. end
  120. end
  121.  
  122. -- no touchy
  123. local path
  124. local waypoint
  125. local oldpoints
  126. local isWandering = 0
  127.  
  128. if canWander then
  129. spawn(function()
  130. while isWandering == 0 do
  131. isWandering = 1
  132. local desgx, desgz = hroot.Position.x + math.random(-WanderX, WanderX), hroot.Position.z + math.random(-WanderZ, WanderZ)
  133. human:MoveTo( Vector3.new(desgx, 0, desgz) )
  134. wait(math.random(4, 6))
  135. isWandering = 0
  136. end
  137. end)
  138. end
  139.  
  140. while wait() do
  141. local enemytorso = GetTorso(hroot.Position)
  142. if enemytorso ~= nil then -- if player detected
  143. isWandering = 1
  144. local function checkw(t)
  145. local ci = 3
  146. if ci > #t then
  147. ci = 3
  148. end
  149. if t[ci] == nil and ci < #t then
  150. repeat
  151. ci = ci + 1
  152. wait()
  153. until t[ci] ~= nil
  154. return Vector3.new(1, 0, 0) + t[ci]
  155. else
  156. ci = 3
  157. return t[ci]
  158. end
  159. end
  160.  
  161. path = pfs:FindPathAsync(hroot.Position, enemytorso.Position)
  162. waypoint = path:GetWaypoints()
  163. oldpoints = waypoint
  164. local connection;
  165.  
  166. local direct = Vector3.FromNormalId(Enum.NormalId.Front)
  167. local ncf = hroot.CFrame * CFrame.new(direct)
  168. direct = ncf.p.unit
  169. local rootr = Ray.new(hroot.Position, direct)
  170. local phit, ppos = game.Workspace:FindPartOnRay(rootr, hroot)
  171.  
  172. if path and waypoint or checkw(waypoint) then
  173. if checkw(waypoint) ~= nil and checkw(waypoint).Action == Enum.PathWaypointAction.Walk then
  174. human:MoveTo( checkw(waypoint).Position )
  175. human.Jump = false
  176. end
  177.  
  178. -- CANNOT LET BALDI JUMPS --
  179. --[[if checkw(waypoint) ~= nil and checkw(waypoint).Action == Enum.PathWaypointAction.Jump then
  180. human.Jump = true
  181. connection = human.Changed:connect(function()
  182. human.Jump = true
  183. end)
  184. human:MoveTo( checkw(waypoint).Position )
  185. else
  186. human.Jump = false
  187. end]]
  188.  
  189. --[[hroot.Touched:connect(function(p)
  190. local bodypartnames = GetPlayersBodyParts(enemytorso)
  191. if p:IsA'Part' and not p.Name == bodypartnames and phit and phit.Name ~= bodypartnames and phit:IsA'Part' and rootr:Distance(phit.Position) < 5 then
  192. connection = human.Changed:connect(function()
  193. human.Jump = true
  194. end)
  195. else
  196. human.Jump = false
  197. end
  198. end)]]
  199.  
  200. if connection then
  201. connection:Disconnect()
  202. end
  203.  
  204. else
  205. for i = 3, #oldpoints do
  206. human:MoveTo( oldpoints[i].Position )
  207. end
  208. end
  209. elseif enemytorso == nil and canWander then -- if player not detected
  210. isWandering = 0
  211. path = nil
  212. waypoint = nil
  213. human.MoveToFinished:Wait()
  214. end
  215. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement