Advertisement
Marcel12311

Roblox script add enemy AI

Jan 6th, 2022
1,816
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 1.97 KB | None | 0 0
  1. --[[
  2. INSTRUCTION:
  3. ------------
  4. 1.Create script inside part and put (code below checked name [1])
  5. 2.Create another script inside part and put (code below checked name [2])
  6. 3.Create BodyPosition inside part and don't change name of BodyPosition!
  7. 4.Change attributes of BodyPosition P=3000
  8. 5.Run!
  9.  
  10. my profile:
  11. https://www.roblox.com/users/140427102/profile
  12. Enjoy!
  13. --]]
  14.  
  15. --[1]----
  16. local part = script.Parent
  17. local humanoid = nil
  18. local torso = nil
  19. local debounce = false
  20.  
  21. local part = script.Parent
  22. local humanoid = nil
  23. local torso = nil
  24. local debounce = false
  25.  
  26. while wait(0.010) do
  27.     for i,v in pairs(game.Workspace:GetChildren()) do
  28.         humanoid = v:FindFirstChild("Humanoid")
  29.         torso = v:FindFirstChild("UpperTorso")
  30.        
  31.         if torso and humanoid and humanoid.Health > 0 then
  32.             if (part.Position - torso.Position).Magnitude <= 50 then
  33.                 part.CFrame = CFrame.new(part.Position,torso.Position)
  34.                 if part:FindFirstChild("BodyPosition") and (humanoid.Health > 0 or humanoid.Health > 2) then
  35.                     part.BrickColor = BrickColor.Red()
  36.                     part.BodyPosition.Position = torso.Position
  37.                 end
  38.             else
  39.                 part.CFrame = CFrame.new(part.Position,Vector3.new(51, 2.5, 98))
  40.                 part.BrickColor = BrickColor.new(163, 162, 165)
  41.                 if part:FindFirstChild("BodyPosition") then
  42.                     part.BodyPosition.Position = Vector3.new(51, 2.5, 98)
  43.                 end        
  44.             end
  45.         elseif humanoid and humanoid.Health <= 0 then
  46.             part.CFrame = CFrame.new(part.Position,Vector3.new(51, 2.5, 98))
  47.             part.BrickColor = BrickColor.new(163, 162, 165)
  48.             if part:FindFirstChild("BodyPosition") then
  49.                 part.BodyPosition.Position = Vector3.new(51, 2.5, 98)
  50.             end
  51.         end
  52.     end
  53. end
  54. ------------------
  55.  
  56. --[2]----
  57. local part = script.Parent
  58. local bs = nil
  59. local debounce = false
  60. local function onTouched(otherPart)
  61.     bs = otherPart.Parent:FindFirstChild("Humanoid")
  62.     if bs and debounce == false then
  63.         debounce = true
  64.         bs:TakeDamage(10)
  65.         wait(3)
  66.         debounce = false
  67.     end
  68. end
  69.  
  70. part.Touched:Connect(onTouched)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement