Forsty

Launcher

Jul 28th, 2017
43
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 4.45 KB | None | 0 0
  1. local tool = script.Parent
  2. local canFire = true
  3. local gunWeld
  4.  
  5. -----------------
  6. --| Constants |--
  7. -----------------
  8.  
  9. local GRAVITY_ACCELERATION = 196.2
  10.  
  11. local RELOAD_TIME = tool.Configurations.ReloadTime.Value -- Seconds until tool can be used again
  12. local ROCKET_SPEED = tool.Configurations.RocketSpeed.Value -- Speed of the projectile
  13.  
  14. local MISSILE_MESH_ID = 'http://www.roblox.com/asset/?id=2251534'
  15. local MISSILE_MESH_SCALE = Vector3.new(0.35, 0.35, 0.25)
  16. local ROCKET_PART_SIZE = Vector3.new(1.2, 1.2, 3.27)
  17.  
  18. local RocketScript = script:WaitForChild('Rocket')
  19. local SwooshSound = script:WaitForChild('Swoosh')
  20. local BoomSound = script:WaitForChild('Boom')
  21.  
  22. local attackCooldown = tool.Configurations.AttackCooldown.Value
  23. local damage = tool.Configurations.Damage.Value
  24. local reloadTime = tool.Configurations.ReloadTime.Value
  25.  
  26. local function createEvent(eventName)
  27. local event = game.ReplicatedStorage:FindFirstChild(eventName)
  28. if not event then
  29. event = Instance.new("RemoteEvent", game.ReplicatedStorage)
  30. event.Name = eventName
  31. end
  32. return event
  33. end
  34.  
  35. local updateEvent = createEvent("ROBLOX_RocketUpdateEvent")
  36. local equipEvent = createEvent("ROBLOX_RocketEquipEvent")
  37. local unequipEvent = createEvent("ROBLOX_RocketUnequipEvent")
  38. local fireEvent = createEvent("ROBLOX_RocketFireEvent")
  39.  
  40. updateEvent.OnServerEvent:connect(function(player, neckC0, rshoulderC0)
  41. local character = player.Character
  42. character.Torso.Neck.C0 = neckC0
  43. character.Torso:FindFirstChild("Right Shoulder").C0 = rshoulderC0
  44. gunWeld = character:FindFirstChild("Right Arm"):WaitForChild("RightGrip")
  45. end)
  46.  
  47. equipEvent.OnServerEvent:connect(function(player)
  48. player.Character.Humanoid.AutoRotate = false
  49. end)
  50.  
  51. unequipEvent.OnServerEvent:connect(function(player)
  52. player.Character.Humanoid.AutoRotate = true
  53. end)
  54.  
  55. --NOTE: We create the rocket once and then clone it when the player fires
  56. local Rocket = Instance.new('Part') do
  57. -- Set up the rocket part
  58. Rocket.Name = 'Rocket'
  59. Rocket.FormFactor = Enum.FormFactor.Custom --NOTE: This must be done before changing Size
  60. Rocket.Size = ROCKET_PART_SIZE
  61. Rocket.CanCollide = false
  62.  
  63. -- Add the mesh
  64. local mesh = Instance.new('SpecialMesh', Rocket)
  65. mesh.MeshId = MISSILE_MESH_ID
  66. mesh.Scale = MISSILE_MESH_SCALE
  67.  
  68. -- Add fire
  69. local fire = Instance.new('Fire', Rocket)
  70. fire.Heat = 5
  71. fire.Size = 2
  72.  
  73. -- Add a force to counteract gravity
  74. local bodyForce = Instance.new('BodyForce', Rocket)
  75. bodyForce.Name = 'Antigravity'
  76. bodyForce.force = Vector3.new(0, Rocket:GetMass() * GRAVITY_ACCELERATION, 0)
  77.  
  78. -- Clone the sounds and set Boom to PlayOnRemove
  79. local swooshSoundClone = SwooshSound:Clone()
  80. swooshSoundClone.Parent = Rocket
  81. local boomSoundClone = BoomSound:Clone()
  82. boomSoundClone.PlayOnRemove = true
  83. boomSoundClone.Parent = Rocket
  84.  
  85. -- Finally, clone the rocket script and enable it
  86. -- local rocketScriptClone = RocketScript:Clone()
  87. -- rocketScriptClone.Parent = Rocket
  88. -- rocketScriptClone.Disabled = false
  89. end
  90.  
  91.  
  92. fireEvent.OnServerEvent:connect(function(player, target)
  93. if canFire and player.Character == tool.Parent then
  94. canFire = false
  95.  
  96. -- Create a clone of Rocket and set its color
  97. local rocketClone = Rocket:Clone()
  98. --game.Debris:AddItem(rocketClone, 30)
  99. rocketClone.BrickColor = player.TeamColor
  100. rocketClone.Touched:connect(function(hit)
  101. if hit and hit.Parent and hit.Parent ~= player.Character and hit.Parent ~= tool then
  102. local explosion = Instance.new("Explosion", game.Workspace)
  103. explosion.Position = rocketClone.Position
  104. rocketClone:Destroy()
  105. end
  106. end)
  107.  
  108. spawn(function()
  109. wait(30)
  110. if rocketClone then rocketClone:Destroy() end
  111. end)
  112.  
  113. -- Position the rocket clone and launch!
  114. local spawnPosition = (tool.Handle.CFrame * CFrame.new(2, 0, 0)).p
  115. rocketClone.CFrame = CFrame.new(spawnPosition, target) --NOTE: This must be done before assigning Parent
  116. rocketClone.Velocity = rocketClone.CFrame.lookVector * ROCKET_SPEED --NOTE: This should be done before assigning Parent
  117. rocketClone.Parent = game.Workspace
  118.  
  119. -- Attach creator tags to the rocket early on
  120. local creatorTag = Instance.new('ObjectValue', rocketClone)
  121. creatorTag.Value = player
  122. creatorTag.Name = 'creator' --NOTE: Must be called 'creator' for website stats
  123. local iconTag = Instance.new('StringValue', creatorTag)
  124. iconTag.Value = tool.TextureId
  125. iconTag.Name = 'icon'
  126.  
  127. delay(attackCooldown, function()
  128. canFire = true
  129. end)
  130. end
  131. end)
Add Comment
Please, Sign In to add comment