Anukun_Lucifer

TowerAttack

Nov 5th, 2023
990
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 0.60 KB | Gaming | 0 0
  1. local tower = script.Parent
  2. local mob = workspace.Grassland.Mob
  3.  
  4. local function FindNearestTarget()
  5.     local maxDistance = 20
  6.     local nearestTarget = nil
  7.    
  8.     for i, target in ipairs(mob:GetChildren()) do
  9.         local distance = (target.HumanoidRootPart.Position - tower.Position).Magnitude
  10.         if distance < maxDistance then
  11.             nearestTarget = target
  12.             maxDistance = distance
  13.         end
  14.     end
  15.    
  16.     return nearestTarget
  17. end
  18.  
  19. while true do
  20.     local target = FindNearestTarget()
  21.     if target then
  22.         local soundshot = script.Parent.Shot
  23.         soundshot:Play()
  24.         target.Humanoid:TakeDamage(25)
  25.     end
  26.     task.wait(0.3)
  27. end
Tags: Roblox
Add Comment
Please, Sign In to add comment