Pro_Pastebin_Person1

Untitled

Apr 24th, 2020
56
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.50 KB | None | 0 0
  1. local Player = game.Players.LocalPlayer.Name
  2. local Gun = "Remington 870" -- < -- Gun Name
  3. local Run = game:GetService("RunService")
  4.  
  5. Gun = game.Players[Player].Character[Gun]
  6. local Mouse = game.Players.LocalPlayer:GetMouse()
  7. local Down = false
  8. local Sound = Gun.Handle.FireSound
  9.  
  10. function CreateRay(Point_A, Point_B)
  11. local Ray = Ray.new(Point_A, (Point_B - Point_A).Unit * (2 ^ 31 - 1))
  12. local Part, Pos = workspace:FindPartOnRay(Ray, game.Players.LocalPlayer.Character)
  13. local Dist = (Point_A - Pos).Magnitude
  14. local CFrame = CFrame.new(Point_A, Pos) * CFrame.new(0, 0, -Dist / 2)
  15.  
  16. return CFrame, Dist, Ray
  17. end
  18.  
  19. function FireLaser(target)
  20. coroutine.resume(coroutine.create(function()
  21. local C, D, R = CreateRay(Gun.Muzzle.CFrame.p, target.CFrame.p)
  22. local Bullet = Instance.new("Part", Gun)
  23. Bullet.BrickColor = BrickColor.Yellow()
  24. Bullet.Material = "Neon"
  25. Bullet.Anchored = true
  26. Bullet.CanCollide = false
  27. Bullet.Size = Vector3.new(0.2, 0.2, D)
  28. Bullet.CFrame = C
  29.  
  30. local bulletTable = {}
  31. table.insert(bulletTable, {
  32. Hit = target,
  33. Distance = D,
  34. Cframe = C,
  35. RayObject = R
  36. })
  37.  
  38. game.ReplicatedStorage.ShootEvent:FireServer(bulletTable, Gun)
  39. local C = Sound:Clone()
  40. C.Parent = Gun
  41. C:Play()
  42. wait(0.05)
  43. Bullet:Remove()
  44. end))
  45. end
  46.  
  47. Mouse.Button1Down:Connect(function()
  48. Down = true
  49. end)
  50.  
  51.  
  52. Mouse.Button1Up:Connect(function()
  53. Down = false
  54. end)
  55.  
  56. while Run.Stepped:wait() do
  57. if Down == true then
  58. game.ReplicatedStorage.SoundEvent:FireServer(Sound, Gun)
  59. FireLaser(Mouse.Target)
  60. end
  61. end
Add Comment
Please, Sign In to add comment