local player = game.Players.LocalPlayer
local enemy = Instance.new("Model")
enemy.Name = "FlyingEnemy"
enemy.Parent = workspace
local humanoid = Instance.new("Humanoid")
humanoid.Parent = enemy
local enemyPart = Instance.new("Part")
enemyPart.Size = Vector3.new(2, 2, 2)
enemyPart.BrickColor = BrickColor.new("Bright red")
enemyPart.Anchored = false
enemyPart.CanCollide = false
enemyPart.Parent = enemy
local function flyTowardsPlayer()
while true do
wait(0.1)
if (enemyPart.Position - player.Character.HumanoidRootPart.Position).magnitude < 50 then
local direction = (player.Character.HumanoidRootPart.Position - enemyPart.Position).unit
enemyPart.Velocity = direction * 50
local bullet = Instance.new("Part")
bullet.Size = Vector3.new(0.5, 0.5, 0.5)
bullet.BrickColor = BrickColor.new("Bright yellow")
bullet.Position = enemyPart.Position
bullet.Anchored = false
bullet.CanCollide = false
bullet.Parent = workspace
local bulletDirection = (player.Character.HumanoidRootPart.Position - bullet.Position).unit
bullet.Velocity = bulletDirection * 100
game.Debris:AddItem(bullet, 5) -- Remove bullet after 5 seconds
end
end
end
flyTowardsPlayer()