How To Make A Rocket Launcher

Hello! In this tutorial I will teach you how to make a rocket launcher, lets get started. First you will need a rocket launcher parts/union/part, and a rocket part/union.

Setting Up Needed Items


After you have those you want to name your rocket launcher “Handle” (or if your rocket launcher is multiple parts then name one of them “Handle”) and put it into a tool. For the rocket, you want to put it into replicated storage and name it “Rocket.” Then put a LocalScript into your tool, a Script into your tool,a script into ServerScriptService, and RemoteEvent into your tool. Name the RemoteEvent “Fire” and put your tool into StarterPack.

Next insert a RemoteEvent into ReplicatedStorage and name it the same as the RemoteEvent in your tool. Also you need to insert a part into your tool and call it “RocketHole”, put it at the front of your rocket launcher, adjust it, and weld it to the main part of your rocket launcher. After that insert a LocalScript into StarterPlayerScripts and name it whatever you like (i will go over why we need that in a little bit).


Now that we got everything set up, we can begin scripting the tool.

Scripting The Tool

We are going to script the LocalScript first of course, first we need to setup some variables. One for the tool, one for the fire event in the tools, one for cool down time, and one for debounce. So we will write this in the LocalScript.

local tool = script.Parent
local fireEvent = tool:WaitForChild("Fire")

coolDown = 3 -- Can change value if its is a number
canFire = true

Now we have got all of our needed variables, we can now script the click function. Write this after all of the needed variables.

tool.Equipped:Connect(function(mouse)
mouse.Button1Down:Connect(function()

end)
end)

After that we now script the rest of it with the debounce and cool down. So this is how the shoot function should look

tool.Equipped:Connect(function(mouse)
mouse.Button1Down:Connect(function()
if canFire then
fireEvent:FireServer(mouse.Hit.Position, coolDown)
canFire = false
wait(coolDown)
canFire = true
end
end)
end)

When we fire the fire event and use mouse.Hit.Position, we will use that to make the rocket face the mouse’s hit. But that is all we need to do in the LocalScript, we can now script the server script. First we will put these two variables.

local tool = script.Parent
local fireEvent = tool:WaitForChild("Fire")

After that we will script this.

fireEvent.OnServerEvent:Connect(function(plr, mouseHit, coolDown)
game.ReplicatedStorage.Fire:FireAllClients(plr, mouseHit,tool)
end)

Now i will explain why we need that LocalScript in StarterPlayerScripts. We are going to be using that LocalScript to clone the rocket, because if i did that in a server script there would be delay in the fire (the rocket would be frozen for a few seconds). So when the remote event in ReplicatedStorage gets locally fired, the LocalScript will generate the rocket. So now lets write the function that will clone the rocket in the LocalScript inside StarterPlayerScripts.

Generating The Rocket

game.ReplicatedStorage.Fire.OnClientEvent:Connect(function(plr, mouseHit, tool)
local rocket = game.ReplicatedStorage.Rocket:Clone()
rocket.Parent = workspace
rocket.CFrame = CFrame.new(tool.RocketHole.Position, mouseHit)
end)

Now when we use this the rocket will be at the part you inserted into your tool named “RocketHole” and face the direction of the mouse’s hit. But it doesn’t go anywhere, the reason for that is because we never setup code for it to be able to move to the mouse hit. To do that we have to write this line of code.

local bv = Instance.new("BodyVelocity", rocket)
bv.Velocity = CFrame.new(rocket.Position, mouseHit).LookVector * 100

If you want the rocket to go faster or slower, just adjust the number that the lookvector is multiplied by.
So far the code should look like this.

game.ReplicatedStorage.Fire.OnClientEvent:Connect(function(plr, mouseHit, tool)
local rocket = game.ReplicatedStorage.Rocket:Clone()
rocket.Parent = workspace
rocket.CFrame = CFrame.new(tool.RocketHole.Position, mouseHit)

local bv = Instance.new("BodyVelocity", rocket)
bv.Velocity = CFrame.new(rocket.Position, mouseHit).LookVector * 100
end)

There we have now got the rocket to fire toward your mouse. But what is a rocket launcher if its rockets don’t actually explode? So we need to make a touched function. For now we write this.

rocket.Touched:Connect(function(hit)

end)

After that we need to make it so that when the rocket touches a part it deletes, so it doesn’t go through walls. So the touched function should look like this.

rocket.Touched:Connect(function(hit)
if hit:IsA("BasePart") then
if hit.Parent ~= tool then
rocket:Destroy()
end
end
wait(3)
rocket:Destroy()
end)

Now it is explaining time, when the rocket is hit we check if it is a BasePart, and if it is we check if what ever it is isn’t a descendant of the rocket launcher tool. And if it isn’t, it will destroy the rocket. And we wait three seconds, if the rocket doesn’t hit anything in three seconds, it still gets destroyed. But if it does hit a part that isn’t in the rocket launcher tool, we will fire the RemoteEvent “Fire” in Replicated Storage. So this is what the finished script looks like.

game.ReplicatedStorage.Fire.OnClientEvent:Connect(function(plr, mouseHit, tool)
local rocket = game.ReplicatedStorage.Rocket:Clone()
rocket.Parent = workspace
rocket.CFrame = CFrame.new(tool.RocketHole.Position, mouseHit)

local bv = Instance.new("BodyVelocity", rocket)
bv.Velocity = CFrame.new(rocket.Position, mouseHit).LookVector * 100

rocket.Touched:Connect(function(hit)
if hit:IsA("BasePart") then
if hit.Parent ~= tool then
rocket:Destroy()
game.ReplicatedStorage.Fire:FireServer(rocket.Position, mouseHit)
end
end
wait(3)
rocket:Destroy()
end)
end)

Now we can make the explosion happen after the rocket has hit something.

Making The Explosions

So now we can go to the script we put into ServerScriptService and write this.

game.ReplicatedStorage.Fire.OnServerEvent:Connect(function(plr, rocketPos, mouseHit)
local explosionPart = Instance.new("Part", workspace)
explosionPart.Anchored = true
explosionPart.CanCollide = false
explosionPart.Transparency = 1
explosionPart.Position = rocketPos

end)

You maybe wondering “Why are we making a part?” And the answer to that is because we are gonna implement sound into that part. So insert an explosion sound effect into ReplicatedStorage and call it “ExplosionSound.” Now this is what the code should look like so far.

game.ReplicatedStorage.Fire.OnServerEvent:Connect(function(plr, rocketPos, mouseHit)
local explosionPart = Instance.new("Part", workspace)
explosionPart.Anchored = true
explosionPart.CanCollide = false
explosionPart.Transparency = 1
explosionPart.Position = rocketPos
local expoSound = game.ReplicatedStorage.ExplosionSound:Clone()
expoSound.Parent = explosionPart
expoSound:Play()

end)

There we have got an explosion sound, but we still have no explosions, to fix that we write this.

local explosion = Instance.new("Explosion", workspace)
explosion.Position = explosionPart.Position
wait(3)
explosionPart:Destroy()

There we have made explosions, and we also don’t want to strain the server with the already used explosion part. So we just destroy it after the explosion and sound is done. So this is what the script should look like.

game.ReplicatedStorage.Fire.OnServerEvent:Connect(function(plr, rocketPos, mouseHit)
local explosionPart = Instance.new("Part", workspace)
explosionPart.Anchored = true
explosionPart.CanCollide = false
explosionPart.Transparency = 1
explosionPart.Position = rocketPos
local expoSound = game.ReplicatedStorage.ExplosionSound:Clone()
expoSound.Parent = explosionPart
expoSound:Play()

local explosion = Instance.new("Explosion", workspace)
explosion.Position = explosionPart.Position
wait(3)
explosionPart:Destroy()
end)

We have made the explosions, now we can make an animation and one more detail. So insert an animation into your tool, put your animation id in it, and name it “Shoot.”

So we go back into the Script inside of your tool and write this.

local shootAnim = tool.Parent.Humanoid:LoadAnimation((tool.Shoot))
shootAnim:Play()

For now this is what the script will look like

local tool = script.Parent
local fireEvent = tool:WaitForChild("Fire")

fireEvent.OnServerEvent:Connect(function(plr, mouseHit, coolDown)
game.ReplicatedStorage.Fire:FireAllClients(plr, mouseHit,tool)
local shootAnim = tool.Parent.Humanoid:LoadAnimation((tool.Shoot))
shootAnim:Play()
end)

Now that we have got it to play a shoot animation, we can now add the last detail. If your rocket launcher has a hole that you can see through like this.

Then you can add this one last detail from this tutorial. If a player is in front of you they will be able to see inside of your rocket, and they will see that there is no rocket inside your rocket launcher. But when you shoot, one will magically come out of nowhere. So if you want to fix this, duplicate your rocket from Replicated Storage and put it into your rocket launcher tool (don’t change its name), adjust it to the center of your rocket launcher hole, and weld it to the rocket launcher. So now we go back into the server script that is in your rocket launcher tool and write this.

tool.Rocket.Transparency = 1
wait(coolDown)
tool.Rocket.Transparency = 0

So whenever you shoot the rocket inside of your rocket launcher goes invisible, and when your cool down time has finished it will be visible again. so this is what the finished script should look like.

local tool = script.Parent
local fireEvent = tool:WaitForChild("Fire")

fireEvent.OnServerEvent:Connect(function(plr, mouseHit, coolDown)
game.ReplicatedStorage.Fire:FireAllClients(plr, mouseHit,tool)
local shootAnim = tool.Parent.Humanoid:LoadAnimation((tool.Shoot))
shootAnim:Play()
tool.Rocket.Transparency = 1
wait(coolDown)
tool.Rocket.Transparency = 0
end)

Well that is the end of the tutorial, i hope you found this helpful! If i misspelled anything, did anything wrong, something isn’t working, ect. Please tell me, and thanks for reading this tutorial.

EDIT

02Alien Pointed out using Debris to remove the rocket and explosion part which is a better idea. Here is the updated ServerScriptService script, and rocket generation script.

ServerScriptServiceScript:

local debris = game:GetService("Debris")

game.ReplicatedStorage.Fire.OnServerEvent:Connect(function(plr, rocketPos, mouseHit)
local explosionPart = Instance.new("Part", workspace)
explosionPart.Anchored = true
explosionPart.CanCollide = false
explosionPart.Transparency = 1
explosionPart.Position = rocketPos
local expoSound = game.ReplicatedStorage.ExplosionSound:Clone()
expoSound.Parent = explosionPart
expoSound:Play()



local explosion = Instance.new("Explosion", workspace)
explosion.Position = explosionPart.Position
debris:AddItem(explosionPart, 3)
end)

Rocket Generation Script:

local debris = game:GetService("Debris")

game.ReplicatedStorage.Fire.OnClientEvent:Connect(function(plr, mouseHit, tool)
local rocket = game.ReplicatedStorage.Rocket:Clone()
rocket.Parent = workspace
rocket.CFrame = CFrame.new(tool.RocketHole.Position, mouseHit)

local bv = Instance.new("BodyVelocity", rocket)
bv.Velocity = CFrame.new(rocket.Position, mouseHit).LookVector * 100

rocket.Touched:Connect(function(hit)
if hit:IsA("BasePart") then
if hit.Parent ~= tool then
rocket:Destroy()
game.ReplicatedStorage.Fire:FireServer(rocket.Position, mouseHit)
end
end
debris:AddItem(rocket, 3)
end)
end)

Finished Product: Rocket Launcher - Roblox

59 Likes

Good job on the tutorial, even I am not planning to use it.

By the way, you might want to do some indent there.

9 Likes

Thanks, for the feedback and the indent thing most likely happened because i was tired while doing so.

2 Likes

I’m planning on making an FPS game so this will be of great help!

4 Likes

Does anyone know how to make an animation exported the way they did? Mine always exports as multiple keyframes.

3 Likes

Can you show me a picture of it so i can get a better understanding?

I can in a few hours, i don’t have studio with me sorry

Its okay, and if you didn’t save the KeySequence to roblox, that maybe why it is multiple keyframes possibly.

One change I would make, rather than waiting and using the Destroy() method, I would use DebrisService to cleanup parts. Documentation on the wiki.. It’s a far far cleaner way to do it, and saves you from yielding the thread as well as preventing errors if the rocket is destroyed before those three seconds are up by something else.

2 Likes

Thanks, i totally somehow forgot Debris even existed.

great tutorial, i think you should put a video of the finished product or make a test game with the rocket launcher so people can test it out

1 Like

Yeah i was going to do that but i forgot after i was testing it to make sure i made no errors while making the tutorial. But there is a finished product place for it now.

Every time the tool is equipped you’re connecting a new event. That’s a pretty big memory leak.

2 Likes

please clean the code, lol.

(30 chars)

The rocket doesnt actually move, it just explodes in the position it was set at.

2 Likes

How would you fix this memory leak @K0VACK?

@bomb2015
Could you possibly un-copylock your final product, so it’s easier to play with the code without copying it all?

  • thanks!

I think you would need to manually disconnect the event.

1 Like

just use tool.Activated