Advertisement
Hasli4

RBLX. CreateEnemy

May 15th, 2025
238
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 0.93 KB | None | 0 0
  1. local MAX_ENEMY_SPEED = 50
  2. local cooldown = 2
  3.  
  4. local ServerStorage = game:GetService("ServerStorage")
  5. local Gun = script.Parent
  6. local start = Gun.GunStart.Position
  7. local target = Gun.Position
  8.  
  9. while true do
  10.     local enemy = ServerStorage.Enemies.EnemyShip:Clone()
  11.     enemy.Parent = workspace.Enemies
  12.     enemy.BrickColor = BrickColor.Random()
  13.     local Gun_X = Gun.Position.X
  14.     local Gun_Y = Gun.Position.Y
  15.     local Gun_Z = Gun.Position.Z
  16.     local ForwardVector = Vector3.new(Gun_X, 0, Gun_Z) -                        Vector3.new(start.X, 0, start.Z)
  17.     enemy.Position = Vector3.new(Gun_X , Gun_Y + enemy.Size.Y, Gun_Z) + ForwardVector
  18.  
  19.     local unit_vector = ForwardVector / ForwardVector.magnitude
  20.     enemy.Position = Vector3.new(Gun_X + unit_vector.X*enemy.Size.X,
  21.         Gun_Y + enemy.Size.Y,
  22.         Gun_Z + unit_vector.Z*enemy.Size.Z)
  23.     local rand_vel = MAX_ENEMY_SPEED * (math.random() + 1)
  24.     enemy.Velocity = unit_vector * rand_vel
  25.     wait(cooldown)
  26. end
  27.  
  28.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement