Advertisement
Guest User

Untitled

a guest
Feb 26th, 2022
87
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.91 KB | None | 0 0
  1. wait(5)
  2.  
  3. local FastCast = require(game.ReplicatedStorage.FastCastRedux)
  4. local PartCache = require(game.ReplicatedStorage.PartCache)
  5.  
  6. local bulletsFolder = workspace:FindFirstChild("BulletFolder") or Instance.new("Folder", workspace)
  7. bulletsFolder.Name = "BulletFolder"
  8.  
  9. local bulletTemplate = game.ReplicatedStorage.CosmeticBullet
  10.  
  11. local caster = FastCast.new()
  12.  
  13. local castParams = RaycastParams.new()
  14. castParams.FilterType = Enum.RaycastFilterType.Blacklist
  15. castParams.FilterDescendantsInstances = {script.Parent}
  16. castParams.IgnoreWater = true
  17.  
  18. local bulletCache = PartCache.new(bulletTemplate, 100, bulletsFolder)
  19.  
  20. local castBehavior = FastCast.newBehavior()
  21. castBehavior.RaycastParams = castParams
  22. castBehavior.Acceleration = Vector3.new(0, 0, 0)
  23. castBehavior.AutoIgnoreContainer = false
  24. castBehavior.CosmeticBulletContainer = bulletsFolder
  25. castBehavior.CosmeticBulletProvider = bulletCache
  26.  
  27. local function onLengthChanged(cast, lastPoint, direction, length, velocity, bullet)
  28. if bullet then
  29. local bulletLength = bullet.Size.Z/2
  30. local offset = CFrame.new(0, 0, -(length - bulletLength))
  31. bullet.CFrame = CFrame.lookAt(lastPoint, lastPoint + direction):ToWorldSpace(offset)
  32. end
  33. end
  34.  
  35. local function onRayHit(cast, result, velocity, bullet)
  36. local hit = result.Instance
  37.  
  38. local character = hit:FindFirstAncestorWhichIsA("Model")
  39. if character and character:FindFirstChild("Humanoid") then
  40. character.Humanoid:TakeDamage(50)
  41. end
  42.  
  43. delay(2, function()
  44. bulletCache:ReturnPart(bullet)
  45. end)
  46. end
  47.  
  48. local turretJoint = script.Parent.Main.Upper.TurretJoint
  49. local mainJoint = script.Parent.Main.Joint
  50. local cooldown = false
  51.  
  52. local damage = 10
  53. local fireRate = 0.02
  54. local distance = 200
  55.  
  56. local function GetClosestCharacter (fromPosition, range)
  57. local bestMagnitude = 1000000
  58. local closestChar = nil
  59. for i, v in ipairs(game.Players:GetChildren()) do
  60. local char = v.Character
  61. local head = char.Head
  62. local distance = (fromPosition - head.Position).Magnitude
  63. if distance < bestMagnitude and distance < range and char.Humanoid.Health > 0 then
  64. bestMagnitude = distance
  65. closestChar = char
  66. end
  67. end
  68. return closestChar
  69. end
  70.  
  71. while wait(fireRate) do
  72. local target = nil
  73. if script.Parent.Active.Value == true then
  74. local char = GetClosestCharacter(turretJoint.Position, distance)
  75. if char then
  76. turretJoint.CFrame = turretJoint.CFrame:Lerp(CFrame.new(turretJoint.Position, char.HumanoidRootPart.Position), 0.5)
  77. mainJoint.Orientation = Vector3.new(0,turretJoint.Orientation.Y,0)
  78. if cooldown == false then
  79. local origin = script.Parent.Main.Upper.FirePoint.Position
  80. local direction = (char.HumanoidRootPart.Position - origin).Unit
  81. cooldown = true
  82. caster:Fire(origin, direction, 1000, castBehavior)
  83. delay(2, function()
  84. cooldown = false
  85. end)
  86. end
  87. end
  88. end
  89. end
  90.  
  91. caster.LengthChanged:Connect(onLengthChanged)
  92. caster.RayHit:Connect(onRayHit)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement