Ok this may be like the 40th FPS tutorial but I’m going to make this beginner friendly (hopefully). I will not be using OOP but I will still use module scripts
Why did you make a “beginner” tutorial instead of an advanced one?
When I first tried making an fps framework, I didn’t know what to look for and watch out for. I remade my fps framework 3 times to actually make it somewhat usable (it wasn’t great). This tutorial aims to teach you the concept and ideas of how to make one and in no way supposed to give you a polished fps framework.
Before continuing, you need to have some knowledge on:
- Roblox lua
- Module scripts
- CFrames
- Moon Animator or Roblox Animator ( or if you know how to animate in blender, use blender )
Objectives:
- Make a basic framework
- Make the gun shoot (duh)
- Make a projectile module
If you have any question you can ask in here
I’ll explain how to make bullet replication, hit detection and aiming in a part 2, tell me if you want a part 2 lol
( also for some reason the videos doesn’t load sometimes )
Step 1: Preparation
To make an FPS game you will need a viewmodel or fake arms.
Here is the viewmodel I used: viewmodel.rbxm (5.2 KB)
First we’re gonna Motor6D the viewmodel. We’re basically creating bones for the viewmodel or welding the parts / limbs.
If your viewmodel has accessories just Motor6D the accessory to the arm (or to whatever the accessory is resting on). Now Motor6D both arms to the HumanoidRootPart
(Part0 = HumanoidRootPart, Part1 = RightArm, same goes for the left arm).
Last thing, make a Motor6D called ‘Handle’ that is where we will weld the gun to the arm.
(Part0 = HumanoidRootPart, Part 1 = nil)
Your viewmodel needs to have a CameraBone (basically just another HRP), then Motor6D the HumanoidRootPart to the CameraBone .
(Part0 = CameraBone, Part1 = HumanoidRootPart)
Now your viewmodel hierarchy should look something like this
(also if your viewmodel has a humanoid, delete it, we’re going to load animations use AnimationController)
After your done put the Viewmodel inside ReplicatedStorage, lets talk about the gun
Here is the gun I used: groza.rbxm (8.7 KB)
You can have any gun you want, the less part the better. We’re not going to Motor6D the gun yet, we will handle that later.
We’re going to make the gun components (aka parts that are going to be used in scripts) You must have the barrel, handle, sight. Put all of those in a folder called “GunComponents”
After your done, put the gun in ReplicatedStorage (oh yeah the ‘Sight’ part does nothing because I’m not going to teach you how to aim in this post, maybe later).
Step 2: Positioning the viewmodel
First lets make a LocalHandler, you can put the script in StarterPlayerScripts. Now make a module scripts in ReplicatedStorage, I’m going to name this module script… ‘MainModule’ very creative, I know. Although we’re going to put a lot unrelated functions, I’m just going to name it MainModule so I don’t confuse you guys.
Alright now lets make so the viewmodel attachees to the camera. How we are going to do this is we’re going to position the viewmodel to the camera every frame.
First open the LocalHandler and parent the Viewmodel to the Camera. So it’s easier to find the viewmodel.
If you test it now nothing will happen, now open your MainModule and make this function:
This will position the viewmodel’s HumanoidRootPart to the Camera’s CFrame. Then we will want it to update it every frame, Just attach this function inside a RenderStepped!
Now it will update every frame! Now you should have something like this:
Step 3: Animating and positioning the gun
Before we position and animate the gun, do you remember when I said this?
We’re going to do that real quick!
Alright lets make a function for welding guns, I’m gonna call it module.weldgun(gun)
. The concept is that we will pass a gun object, and get the parts and weld it all to the handle.
(VERY VERY important note: make sure you add if v ~= Main then
or else when animating it will crash moon animator)
Alright we have our weldgun function now lets call it in the LocalHandler
Now we have that out of the way, first step is to make it so the gun welds to the viewmodel. Let’s make an module.equip(viewmodel, gun)
function.
We’re basically setting the Motor6D to the gun’s handle. Now the gun is in your face! no!!
Time for some animating! First we need to get the viewmodel with the gun so first play the game and then go to Workspace > Camera > Viewmodel. Make sure the gun is also inside the viewmodel, then copy the viewmodel, then stop playing and paste. (make sure the gun is oriented correctly!! if not check the the gun’s handle orientation). Now you should have something like this
We need to rotate the viewmodel correctly first before animating, so just select the HumanoidRootPart and set its position to 0, 0, 0
(optional) and the rotation to 0, 0, 0
Voila!! Lets get animating. Now we want to make a hold animation. Just put the viewmodel inside moon animator and start animating! In the end you should have something like this
Make sure it’s looped and when your done, publish the animation!
Alright now you have your holding animations, lets actually play the animation, but before we do that. Lets make a folder containing the gun’s animations. Inside we put the holding animation, I just named it “Hold”.
Alright! Now lets edit the module.equip(viewmodel, gun)
function. We’re gonna add a new parameter called ‘hold’.
anddd in the LocalHandler
Lets give it a try
andddd
Voila!! The animation works! If it dosen’t work for you check the animation and the Motor6D and also make sure the Animation object is valid.
Step 4: Projectile module
I’m just going to make a basic projectile module, you can skip this step if you know how to use FastCast
Alright so in the MainModule let’s make a new function called module.cast()
. The idea is that it will create a bullet and then position it self to the barrel facing to the mouse position then making the bullet go forward.
First step: Making the bullet go to the barrel
Later we will pass 3 information, the gun, the end position and the velocity of the bullet or studs per frame
Second step: Making the bullet go forward
We will use a RenderStepped to make the bullet travel smoothly
We’re multiplying the -velocity with dt is because the bullet velocity will adjust to frame drops or when framerate goes higher or lower
Third step: Destroying the bullet when it goes too far
Step 5: Making the gun shoot
We’re gonna write some code that detects if the player is holding the mouse or not
Now lets check if the player is holding or not, if if the player is holding then fire the gun.
andddd
We’re finished! The gun dosen’t do much… but I’ll continue this tutorial if people think I’m worthy enough to continue this. 20 hearts and I’ll do a part 2! If it there was a part 2, I would probably teach you how to make recoil, bullet replication and hit detection (let me know what gun feature do you want). Part 2 is out now!
Code:
LocalHandler:
MainModule:
(Part 2 coming tomorrow!!)
edit: part 2 might be delayed sorry!!
Part 2 is here (finally)!!
If you have any questions you can join the discord server