Prephy

Rocket launcher

May 7th, 2021 (edited)
676
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. --ROBLOX's rocket launcher tool remade and converted by Protofer_S, feel free to use it!
  2.  
  3.  
  4.  
  5. local tool = Instance.new("Tool")
  6. tool.Archivable=true
  7. tool.CanBeDropped=false tool.RequiresHandle=true
  8. local handle = Instance.new("Part",tool)  handle.Name='Handle'
  9. handle.Size=Vector3.new(4.92, 0.74, 0.84)
  10. tool.GripForward=Vector3.new(1,0,0)
  11. tool.GripPos=Vector3.new(0.7, 0, -0.5)
  12. tool.GripRight=Vector3.new(0, -1, 0)
  13. tool.GripUp=Vector3.new(0,0,1)
  14.  
  15. print('Made by Protofer_S')
  16.  
  17. local handle_mesh = Instance.new("SpecialMesh",handle) handle_mesh.MeshId='rbxasset://fonts/rocketlauncher.mesh'
  18. handle_mesh.TextureId='rbxasset://textures/rocketlaunchertex.png' handle_mesh.Scale=Vector3.new(0.75, 0.75, 0.75)
  19. tool.TextureId='http://www.roblox.com/asset/?id=90021376'
  20.  
  21. tool.Parent=owner.Backpack
  22.  
  23.  
  24.  
  25.  
  26.  
  27. function functions()
  28.  
  29.     NLS([[
  30.  
  31.    
  32.     local Tool = script.Parent
  33.  
  34. local Remote = Tool:WaitForChild("MouseLoc")
  35.  
  36. local Mouse = game.Players.LocalPlayer:GetMouse()
  37.  
  38. function Remote.OnClientInvoke()
  39.     return Mouse.Hit.p
  40. end
  41.    
  42.    
  43.    
  44.    
  45.    
  46.    
  47.    
  48.     ]],handle.Parent)
  49.  
  50.     NLS([[
  51.    
  52.     local MOUSE_ICON = 'rbxasset://textures/GunCursor.png'
  53. local RELOADING_ICON = 'rbxasset://textures/GunWaitCursor.png'
  54.  
  55. local Tool = script.Parent
  56.  
  57. local Mouse = nil
  58.  
  59. local function UpdateIcon()
  60.     if Mouse then
  61.         Mouse.Icon = Tool.Enabled and MOUSE_ICON or RELOADING_ICON
  62.     end
  63. end
  64.  
  65. local function OnEquipped(mouse)
  66.     Mouse = mouse
  67.     UpdateIcon()
  68. end
  69.  
  70. local function OnChanged(property)
  71.     if property == 'Enabled' then
  72.         UpdateIcon()
  73.     end
  74. end
  75.  
  76. Tool.Equipped:Connect(OnEquipped)
  77. Tool.Changed:Connect(OnChanged)
  78.  
  79.    
  80.    
  81.    
  82.    
  83.     ]],handle.Parent)
  84.  
  85.  
  86. end
  87.  
  88. functions()
  89. -----------------
  90. --| Constants |--
  91. -----------------
  92.  
  93. local GRAVITY_ACCELERATION = workspace.Gravity
  94.  
  95. local RELOAD_TIME = 1 -- Seconds until tool can be used again
  96. local ROCKET_SPEED = 100 -- Speed of the projectile
  97.  
  98. local ROCKET_PART_SIZE = Vector3.new(1,1,4)
  99. --local MISSILE_MESH_ID = 'http://www.roblox.com/asset/?id=2251534'
  100. --local MISSILE_MESH_SCALE = Vector3.new(0.35, 0.35, 0.25)
  101.  
  102. -----------------
  103. --| Variables |--
  104. -----------------
  105.  
  106. local DebrisService = game:GetService('Debris')
  107. local PlayersService = game:GetService('Players')
  108.  
  109. local MyPlayer
  110.  
  111. local Tool = tool
  112. local ToolHandle = handle
  113. local MouseLoc = Instance.new("RemoteFunction",tool) MouseLoc.Name='MouseLoc'
  114.  
  115. --local RocketScript = script:WaitForChild('Rocket')
  116. --local SwooshSound = Instance.new("Sound") SwooshSound.SoundId='rbxasset://sounds/Rocket whoosh 01.wav' SwooshSound.Looped=true
  117. --local BoomSound = Instance.new("Sound") BoomSound.PlayOnRemove=true BoomSound.Volume=0.7 BoomSound.SoundId='rbxasset://sounds/Rocket whoosh 01.wav'
  118.  
  119. --NOTE: We create the rocket once and then clone it when the player fires
  120. local Rocket = Instance.new('FlagStand') do
  121.     -- Set up the rocket part
  122.     Rocket.Name = 'Rocket'
  123.     Rocket.FormFactor = Enum.FormFactor.Custom --NOTE: This must be done before changing Size
  124.     Rocket.Size = ROCKET_PART_SIZE
  125.     Rocket.CanCollide =  true--false
  126.  
  127.     -- Add the mesh
  128.     --local mesh = Instance.new('SpecialMesh', Rocket)
  129.     --mesh.MeshId = MISSILE_MESH_ID
  130.     --mesh.Scale = MISSILE_MESH_SCALE
  131.  
  132.     -- Add fire
  133.     --local fire = Instance.new('Fire', Rocket)
  134.     --fire.Heat = 5
  135.     --fire.Size = 2
  136.  
  137.     -- Add a force to counteract gravity
  138.     local bodyForce = Instance.new('BodyForce', Rocket)
  139.     bodyForce.Name = 'Antigravity'
  140.     bodyForce.Force = Vector3.new(0, Rocket:GetMass() * GRAVITY_ACCELERATION, 0)
  141.  
  142.     -- Clone the sounds and set Boom to PlayOnRemove
  143.     local swooshSoundClone = Instance.new("Sound") swooshSoundClone.SoundId='rbxasset://sounds/Rocket whoosh 01.wav' swooshSoundClone.Looped=true swooshSoundClone.Name='Swoosh' swooshSoundClone.Volume=0.7--SwooshSound:Clone()
  144.     swooshSoundClone.Parent = Rocket swooshSoundClone:Play()
  145.     local boomSoundClone =   Instance.new("Sound")  boomSoundClone.Volume=0.7 boomSoundClone.SoundId='rbxasset://sounds/collide.wav'    boomSoundClone.Name='Boom' boomSoundClone.Volume=1 --BoomSound:Clone()
  146.     boomSoundClone.PlayOnRemove = true
  147.     boomSoundClone.Parent = Rocket
  148.  
  149.     -- Attach creator tags to the rocket early on
  150.     local creatorTag = Instance.new('ObjectValue', Rocket)
  151.     creatorTag.Value = MyPlayer
  152.     creatorTag.Name = 'creator' --NOTE: Must be called 'creator' for website stats
  153.     local iconTag = Instance.new('StringValue', creatorTag)
  154.     iconTag.Value = Tool.TextureId
  155.     iconTag.Name = 'icon'
  156.  
  157.  
  158.  
  159.     function rocketfunctions(rocket)
  160.         local BLAST_RADIUS = 10 -- Blast radius of the explosion
  161.         local BLAST_FORCE = 600000 -- Amount of force applied to parts
  162.         local swoosh=rocket:waitForChild('Swoosh')
  163.         local function explode(victim)
  164.            
  165.             local beam= Instance.new("Explosion",workspace) beam.Position=rocket.Position
  166.             beam.BlastRadius = BLAST_RADIUS
  167.             beam.BlastPressure=BLAST_FORCE
  168.             beam.ExplosionType = Enum.ExplosionType.Craters
  169.             beam.Hit:Connect(function(part,distance)
  170.                
  171.                 local hum = part.Parent:FindFirstChildOfClass('Humanoid')
  172.                 if hum then
  173.                if hum.MaxHealth>110 then
  174.          hum.Health=0 hum.MaxHealth=-20
  175.            hum.Parent:BreakJoints()
  176.  
  177.        end
  178.                     local bad = hum.Parent:FindFirstChildOfClass('ForceField')
  179.                     if bad then
  180.                         bad:Destroy()
  181.                         hum.Parent:BreakJoints()
  182.                         wait(.2)
  183.                         hum:Destroy()
  184.                     end
  185.                 end
  186.             end)
  187.             swoosh:Pause()
  188.             rocket:Destroy()
  189.            
  190.            
  191.         end
  192.        
  193.        
  194.        
  195.         rocket.Touched:Connect(explode)
  196.        
  197.     end
  198.  
  199.     -- Finally, clone the rocket script and enable it
  200.     --local rocketScriptClone = RocketScript:Clone()
  201.     --rocketScriptClone.Parent = Rocket
  202.     --rocketScriptClone.Disabled = false
  203. end
  204.  
  205. -----------------
  206. --| Functions |--
  207. -----------------
  208.  
  209. local function OnActivated()
  210.     local myModel = MyPlayer.Character
  211.     if Tool.Enabled and myModel and myModel:FindFirstChildOfClass("Humanoid") and myModel.Humanoid.Health > 0 then
  212.         Tool.Enabled = false
  213.         local Pos = MouseLoc:InvokeClient(MyPlayer)
  214.         -- Create a clone of Rocket and set its color
  215.         local rocketClone = Rocket:Clone()
  216.         rocketfunctions(rocketClone)
  217.         DebrisService:AddItem(rocketClone, 30)
  218.         rocketClone.BrickColor = BrickColor.new("Bright blue")
  219.  
  220.         -- Position the rocket clone and launch!
  221.         local spawnPosition = (ToolHandle.CFrame * CFrame.new(5, 0, 0)).p
  222.         rocketClone.CFrame = CFrame.new(spawnPosition, Pos) --NOTE: This must be done before assigning Parent
  223.         rocketClone.Velocity = rocketClone.CFrame.lookVector * ROCKET_SPEED --NOTE: This should be done before assigning Parent
  224.         rocketClone.Parent = workspace
  225.         rocketClone:SetNetworkOwner(nil)
  226.         rocketClone.Material=Enum.Material.Plastic
  227.  
  228.         wait(RELOAD_TIME)
  229.  
  230.         Tool.Enabled = true
  231.     end
  232. end
  233.  
  234. function OnEquipped()
  235.     MyPlayer = PlayersService:GetPlayerFromCharacter(Tool.Parent)
  236. end
  237.  
  238. --------------------
  239. --| Script Logic |--
  240. --------------------
  241.  
  242.  
  243.  
  244.  
  245.  
  246. tool.Equipped:Connect(OnEquipped)
  247. tool.Activated:Connect(OnActivated)
  248.  
  249.  
RAW Paste Data