Advertisement
RobertCodez

Bow and Arrow - Roblox

Jul 19th, 2021
582
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 2.71 KB | None | 0 0
  1.  
  2. local player = game.Players.LocalPlayer
  3. local playerGUI = player:WaitForChild('PlayerGui')
  4. local Mouse = player:GetMouse()
  5.  
  6. local RS = game:GetService("RunService")
  7. local Debris = game:GetService("Debris")
  8.  
  9. local Handle = script.Parent.Handle
  10. local Ammo = player.BowAmmo
  11. local MaxAmmo = 20
  12. local reloading = false
  13. local debounce = true
  14.  
  15. local FireAnimation = script.Parent:WaitForChild("Fire")
  16. local IdleAnimation = script.Parent:WaitForChild("Idle")
  17. local LoadAnimation = script.Parent:WaitForChild("Load")
  18. playerGUI.AmmoGUI.BG.Visible = true
  19. local character = player.Character or player.CharacterAdded:Wait()
  20. local Hum = character:WaitForChild("Humanoid")
  21.  
  22. local IdleTrack = Hum:LoadAnimation(IdleAnimation)
  23. local LoadTrack = Hum:LoadAnimation(LoadAnimation)
  24.  
  25. script.Parent.Equipped:Connect(function()
  26.     playerGUI.AmmoGUI.BG.Visible = true
  27.    
  28.     IdleTrack:Play()
  29. end)
  30. script.Parent.Unequipped:Connect(function()
  31.    
  32.     playerGUI.AmmoGUI.BG.Visible = false
  33.     IdleTrack:Stop()
  34.  
  35. end)
  36.  
  37.  
  38.  
  39.  
  40. script.Parent.Activated:Connect(function()
  41.     -- animation again
  42.     if debounce == true then
  43.         debounce = false
  44.    
  45.     local Fire = script.Parent.Fire
  46.     local Idle = script.Parent.Idle
  47.     local char = player.Character
  48.     local Hum = char.Humanoid
  49.         local Track = Hum:LoadAnimation(Fire)
  50.         LoadTrack:Play()
  51.         LoadTrack.Stopped:Wait()
  52.     Track:Play()
  53.  
  54.     if Ammo.Value > 0 then
  55.        
  56.         Ammo.Value = Ammo.Value -1
  57.         local flying = false
  58.         -- mouse Vars
  59.         local Target = Mouse.Hit
  60.         local Arrow = game.ReplicatedStorage.Arrow:Clone()
  61.         local HandlePosition = Handle.Position
  62.  
  63.  
  64.  
  65.         local HandleOrientation = Handle.CFrame.UpVector * 2
  66.         Arrow.CFrame = CFrame.lookAt(HandlePosition,Target.Position)*CFrame.Angles(0,math.rad(180),0)
  67.         Arrow.BodyVelocity.Velocity = -Arrow.CFrame.LookVector * 200
  68.         Arrow.Parent = game.Workspace
  69.         flying = true
  70.  
  71. local Touched = false
  72.  
  73.  
  74.         Arrow.Touched:Connect(function(hit)
  75.             if hit.Name == 'Bow' then return end
  76.             if hit.Name == 'Handle' then return end
  77.             if hit.Parent == player.Character then return end
  78.             if hit.Name == 'Arrow' then return end
  79.             Arrow.Trail.Transparency = NumberSequence.new(1)
  80.                 Arrow.Anchored = true
  81.                 if hit.Parent:FindFirstChild("Humanoid") then
  82.                     if Touched == false then
  83.                         Touched = true
  84.                         hit.Parent:FindFirstChild("Humanoid"):TakeDamage(75)
  85.                     end
  86.                    
  87.                    
  88.                
  89.             end
  90.             end)
  91.             RS.RenderStepped:Connect(function()
  92.                 if flying == true then
  93.                     if Arrow:FindFirstChild("BodyVelocity") then
  94.                         Arrow.BodyVelocity.Velocity = Arrow.BodyVelocity.Velocity - Vector3.new(0,1,0)
  95.                     end
  96.                    
  97.                    
  98.                 end
  99.                 wait(2)
  100.             end)
  101.            
  102.  
  103.         Debris:AddItem(Arrow, 15)
  104.    
  105.            
  106.        
  107.         end
  108.         wait(2)
  109.         debounce = true
  110.     end
  111.    
  112.    
  113. end)
  114.  
  115.  
  116.  
  117.  
  118.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement