Advertisement
Guest User

Untitled

a guest
Feb 8th, 2016
56
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 3.80 KB | None | 0 0
  1. local Unit = script.Parent
  2. local Bow = Unit.Torso -- Changed this up so script goes into the unit not the weapon now
  3.  
  4. local Humanoid = Unit.Humanoid
  5. local Config = Unit.Config
  6. local Range = Config.Range
  7. local Damage = Config.Damage
  8. local ReloadTime = Config.ReloadTime
  9.  
  10.  ClosestMagnitude = 10000
  11.  ClosestEnemy = nil
  12.  Units = game.Workspace.Units
  13.  Buildings = game.Workspace.Buildings
  14.  
  15.  
  16.  
  17. function Fire()
  18.     if ClosestEnemy ~= nil and ClosestEnemy.Parent == workspace.Units and ClosestMagnitude < Range.Value then
  19.        
  20.     local ray = Ray.new(Bow.CFrame.p, (ClosestEnemy.Torso.CFrame.p - Bow.CFrame.p).unit * 300)
  21.     local beam = Instance.new("Part", workspace)
  22.    
  23.         beam.BrickColor = Unit.TeamColor.Value
  24.         beam.FormFactor = "Custom"
  25.         beam.Material = "Plastic"
  26.         beam.Transparency = 0.5
  27.         beam.Anchored = true
  28.         beam.Locked = true
  29.         beam.CanCollide = false
  30.         game:GetService("Debris"):AddItem(beam, 0.2)
  31.        
  32.     local part, position = workspace:FindPartOnRay(ray, ClosestEnemy.Torso, false, true)
  33.     local distance = (Bow.CFrame.p - position).magnitude
  34.    
  35.         beam.Size = Vector3.new(0.2, 0.2, distance)
  36.          beam.CFrame = CFrame.new(Bow.CFrame.p, position) * CFrame.new(0, 0, -distance / 2)
  37.  
  38.         if part and part.Parent.TeamColor.Value ~= Unit.TeamColor.Value then
  39.            
  40.         local humanoid = part.Parent:FindFirstChild("Humanoid")
  41.  
  42.             if not humanoid then
  43.             local humanoid = part.Parent.Parent:FindFirstChild("Humanoid")
  44.             end
  45.  
  46.             if humanoid then
  47.                 humanoid:TakeDamage(Damage.Value)
  48.             end
  49.         end
  50.    
  51.     else if ClosestEnemy ~= nil and ClosestEnemy.Parent == workspace.Buildings and ClosestMagnitude < Range.Value then --ClosestEnemy.OriginPart < Range.Value was here before? idk
  52.     local ray = Ray.new(Bow.Handle.CFrame.p, (ClosestEnemy.OriginPart.p - Bow.Handle.CFrame.p).unit * 300)
  53.     local beam = Instance.new("Part", workspace)
  54.    
  55.         beam.BrickColor = Unit.TeamColor.Value
  56.         beam.FormFactor = "Custom"
  57.         beam.Material = "Plastic"
  58.         beam.Transparency = 1
  59.         beam.Anchored = true
  60.         beam.Locked = true
  61.         beam.CanCollide = false
  62.         game:GetService("Debris"):AddItem(beam, 0.2)
  63.        
  64.     local part, position = workspace:FindPartOnRay(ray, ClosestEnemy.OriginPart, false, true)
  65.     local distance = (Bow.Handle.CFrame.p - position).magnitude
  66.    
  67.         beam.Size = Vector3.new(0.2, 0.2, distance)
  68.         beam.CFrame = CFrame.new(Bow.Handle.CFrame.p, position) * CFrame.new(0, 0, -distance / 2)
  69.  
  70.  
  71.     if part and part.Parent.TeamColor.Value ~= Unit.TeamColor.Value then
  72.    
  73.     local humanoid = part.Parent:FindFirstChild("Humanoid")
  74.         if not humanoid then
  75.         local humanoid = part.Parent.Parent:FindFirstChild("Humanoid")
  76.         end
  77.         if humanoid then
  78.         humanoid:TakeDamage(Damage.Value)
  79.  
  80.         end
  81.     end
  82.     end
  83.    
  84.    
  85.     end
  86. end
  87.  
  88.  
  89.  
  90.  
  91. while true do -- TIME 2 FIND UNITS
  92. for i,v in pairs(game.Workspace.Units:GetChildren()) do
  93.     local Magnitude = (Unit.Torso.Position - v.Torso.Position).magnitude
  94.     if v.TeamColor.Value ~= Unit.TeamColor.Value and Magnitude < ClosestMagnitude and v ~= Unit then
  95.        
  96.         ClosestMagnitude = Magnitude
  97.         ClosestEnemy = v
  98.        
  99.     elseif v.Torso.Position.Magnitude >= ClosestMagnitude then print('Searching for closest enemy...')
  100.        
  101.     end
  102.    
  103. end
  104.  
  105.  
  106.  
  107. if ClosestMagnitude > Range.Value then --DER ARE NO UNITS, AM SEARCH BUILDINS INSTED
  108. for i,v in pairs(game.Workspace.Buildings:GetChildren()) do
  109.     local Magnitude = (Unit.Torso.Position - v.OriginPart.Position).magnitude
  110.     if v.TeamColor.Value ~= Unit.TeamColor.Value and Magnitude <= ClosestMagnitude and v ~= Unit then
  111.  
  112.         ClosestMagnitude = Magnitude
  113.         ClosestEnemy = v
  114.        
  115.     elseif v.OriginPart.Position.Magnitude <= ClosestMagnitude then print('Searching for closest Building...')  
  116.        
  117.     end
  118.        
  119. end
  120. end
  121.  
  122. Fire()
  123. print(ClosestEnemy.Name)
  124. print(ClosestMagnitude)
  125. wait(ReloadTime.Value)
  126. ClosestMagnitude = 10000
  127. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement