FPS Tutorial [Part 1]

Hello everyone and this is my second fps tutorial and is the first part! I did it as I stated in my last tutorial that I will make a tutorial on advanced systems.

Disclaimer: I am new to FPS making so please point out any errors or mistakes and I will be using the basics of this video here.

In this part we will be covering on how to attach the gun to your face.

Lets begin!
1. Setting up

  • Firstly we will need to set up the game. We will need a few folders in replicated storage to store our guns and their modules.
    It should look like this:
    image
  • Now we will need a viewmodel. I have made one here.
    image
  • And we will need a gun.
    I got a model from the toolbox like this:

2. The viewmodel

  1. Make sure all of the gun parts are unanchored.
    image
  2. Add a part named handle inside the gun and position in on the trigger make sure its facing forward and up.
    image
  3. Weld all of the gun parts to the handle.
    image
  4. Put the gun between the arms and inside the arms model and call it weapon, gun, idk.

    Model:
    image
  5. Lastly weld the handle to the humanoid root part.
    image
    Now drop it in the models folder inside replicated storage and call the viewmodel the guns name.

3. The framework

  • Make a new local script inside starter player ➔ starter character scripts call it whatever you want.
    image
  • Lets start scripting!

We will start by adding a loop to check if the game is loaded.

repeat
	wait()
until game:IsLoaded()

Now we will make a few variables.

repeat
	wait()
until game:IsLoaded()

--[[so let me explain how this will work. So basically we will have a function that will set up the gun to your face and basically make the system more flexible
we will add the function soon]]

local plr = game.Players.LocalPlayer
local char = plr.Character
local mouse = plr:GetMouse()
local cam = workspace.CurrentCamera
local runs = game:GetService("RunService")
local rs = game.ReplicatedStorage
local gunmodels = rs:WaitForChild("models")
local gunmodules = rs:WaitForChild("modules")

local primary = "m4" --our primary gun
local secondary = "" --not yet in use (coming in a  few tutorials)
local currentweapon
local weaponmodule

local maincf = CFrame.new() --we will use this shortly

Now we will add a function that will set up the gun to our face so we dont have to do any complex scripting, how genius.

function setup(weapon) --so the system know what weapon we set up
	
end

setup(primary) --the weapon we set up is getting sent to the function

4. Modules
Great we now will add some gun settings inside a module.

  • Create a module script inside modules and call it the same as the viewmodel.

Now we will add a few settings. one I mean

local settings = {}
settings.maincf = CFrame.new(0, 0, 0) * CFrame.Angles(0, 0, 0) --with this you will be able to edit the guns position
return settings

5. Positioning the gun
Exciting right? We will finally slap the gun to your face.
Lets get back to the framework we got some stuff to do.

--add this inside the setup() function
	weaponmodule = require(gunmodules:WaitForChild(primary))
	
	maincf = weaponmodule.maincf
	
	currentweapon = gunmodels:WaitForChild(primary):Clone()
	currentweapon.Parent = cam

Now we will add the last lines for actually positioning the gun. add this above the setup()

runs.RenderStepped:Connect(function()
	if currentweapon then --we add this so the framework doesnt cry when there is no currentweapon
		currentweapon:SetPrimaryPartCFrame(
			cam.CFrame
			* maincf --we merge the camera cframe with the offset and then set it as the viewmodels position.
		)
	end
end)

End product:


With some playing around:

Thats gonna do it for this tutorial in the next one we will add aiming and maybe animations.
Part 2: FPS Tutorial [Part 2]

As always please point out any script and writing errors and now I will go take a nap.

also the place: Tutorial FPS part 4 - Roblox

34 Likes

This is wonderful! Can’t wait to read part 2.

5 Likes

Oh, and make sure to delete any scripts you find in items from the toolbox as they may contain viruses that may break your game.

2 Likes

You are lucky cuz I just made one!

2 Likes

Why are you using humanoid? Its decrypted and doesn’t work. Use AnimationController instead.

At that time I didn’t really know about it.

New problem. Gun keeps bashing my face

1 Like

change the maincf that should help

1 Like

I am not sure why but it’s not working for me and I want to know why

GwaGwaGu86.rbxl (85.9 KB)

Hey, I look into it and you have to change line 14 and 15 to:

local gunmodels = rs:WaitForChild("Models")
local gunmodules = rs:WaitForChild("Modules")

and rename the module in modules to m4.

2 Likes