But if it does hit a part that isn’t in the rocket launcher tool, we will fire the RemoteEvent “Fire” in Replicated Storage. And we wait three seconds, if the rocket doesn’t hit anything in three seconds, it still gets destroyed. And if it isn’t, it will destroy the rocket. 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. So the touched function should look like this. rocket.Touched:Connect(function(hit)Īfter that we need to make it so that when the rocket touches a part it deletes, so it doesn’t go through walls. But what is a rocket launcher if its rockets don’t actually explode? So we need to make a touched function. There we have now got the rocket to fire toward your mouse. Local bv = Instance.new("BodyVelocity", rocket) If you want the rocket to go faster or slower, just adjust the number that the lookvector is multiplied by. local bv = Instance.new("BodyVelocity", rocket)īv.Velocity = CFrame.new(rocket.Position, mouseHit).LookVector * 100 To do that we have to write this line of code.
#ROCKET LAUNCH AND HYPERSPIN TUTORIAL CODE#
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. 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. Generating The Rocket :Connect(function(plr, mouseHit, tool) So now lets write the function that will clone the rocket in the LocalScript inside StarterPlayerScripts. So when the remote event in ReplicatedStorage gets locally fired, the LocalScript will generate the rocket. 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). Now i will explain why we need that LocalScript in StarterPlayerScripts.
fireEvent.OnServerEvent:Connect(function(plr, mouseHit, coolDown) local tool = script.ParentĪfter that we will script this. But that is all we need to do in the LocalScript, we can now script the server script. When we fire the fire event and use, we will use that to make the rocket face the mouse’s hit. So this is how the shoot function should look tool.Equipped:Connect(function(mouse)įireEvent:FireServer(, coolDown) tool.Equipped:Connect(function(mouse)Īfter that we now script the rest of it with the debounce and cool down. Write this after all of the needed variables. Now we have got all of our needed variables, we can now script the click function. Local fireEvent = tool:WaitForChild("Fire")ĬoolDown = 3 - Can change value if its is a number So we will write this in the LocalScript. One for the tool, one for the fire event in the tools, one for cool down time, and one for debounce. We are going to script the LocalScript first of course, first we need to setup some variables. Now that we got everything set up, we can begin scripting the tool.