How to make a third person gun system

I am trying to make a third person gun system similar to what is used in the video below.
I have found many tutorials on this subject, but they all use different ways to make it, so I was wondering what is the best way to make it?

7:11-8:05

2 Likes

What is your level in Lua programation ?

There is a lot of different way to do it.
A well made gun system can be very complex and long to made, depending on how much detailed you want to do it.

You need to have at least 2 to 3 years of experience in programing, and a advanced programation level to do a gun system, if you are a beginner, i think it would be useless to explain you how to do it, as you will probably don’t understand anything.

Raycasting My Intro to Raycasting - WHAT, WHY, and HOW

I’m probably like semi-advanced, and I have around 1.7 years of experience in Lua programing.

I don’t want to offense you or anything, but like, if you can’t do at least a [classic gun system] with no bugs and made 100% by yourself only using your own knowledge and without following a random tutorial, then you’re not ready to do it yet, you should keep learning coding.

[classic gun system] = Creating a tool, click to shoot, throwing the bullet, play a sound and do damages (without magazine capacity, reloading, animations, Ui, hitmarker, killfeed, camera shake ect…)

There is a list of requirement that you need to perfectly know how to use to do a well made gun system.

  • Using module scripts (Creating functions and call them from other scripts)
  • Remote Event (Remote an action from local to server side, or server to local)
  • Using UIS (User Input Service), to do an action while pressing an input
  • Camera Manipulation (Moving the camera, changing the offset, changing the fov, doing camera effects ect…)
  • Ui scripting (Showing an Ui when equiping a tool and hiding it when tool is unequiped. Updating the ui in real time to show ammo number, optionaly doing a killfeed while killing someone, doing a hitmarker while hiting an enemie ect…)
  • Playing sounds and animations
  • Using raycast or Magnitude (To detect when a part is about to hit another part - bullet to enemies)
  • Using LookVector or TweenService to move a part to a direction or from a point to another point.
  • Optionaly the team or npc system (Detecting if the bullet do damage to everyone or only on players that isn’t in your team, or only on npc.)
1 Like

I have used all these things before, but never to make a gun system.
So if I need to know these things, then making one should be no problem.

What do you mean you have to be 2-3 years experienced in roblox??? Anyone can do it <1.

Alright, so i’m going to try to explain you how to do a simple gun system step by step.

Step 1 [Create the tool]

  • Create a new tool in the workspace, rename it “Weapon”
  • In the tool properties, disable “Can be dropped”
  • Create a new part in the tool, rename the part “Handle”.
  • In the part properties, disable “Cast Shadow”, transparency = 1, disable can collide and anchored, resize it to (0.5, 0.5, 0.5).
  • Import your gun 3D model in the workspace, move it to the “Handle” part position.
    In the meshes properties, disable can collide and anchored.
    The handle position of your gun 3D model should be at the “Handle” part position of the tool.
    This is where your character will take the tool on his hands.
    Make sure to change the orientation of the model, the front face of the “Handle” part, is where your gun should be oriented.
  • When your mesh is placed, weld it to to the “Handle” part, using a weld plugin.

Step 2 [Create the sounds]

  • Create a new folder in the tool, rename it “Sounds”
  • Create 4 new “Sound” in this folder, rename them “Equip”, “Unequip”, “Fire” and “Reload”
  • Take free sounds in the toolbox, or made them, then put the sound id in each of them.
  • Go into the “Unequip” sound properties, and enable “Play on remove”.
  • Make sure to change the volume, and the rolloff max and min distance of each sounds. (min 5, max 35 by default)

You can also add other sounds, like hitmarker and kill but you need to put them into the “Sound Service” and play them localy

Capture2

Step 3 [Create the animations]

  • Create a new folder in the tool, rename it “Animations”
  • Create 2 new “Animation” and put them in the folder, rename them “Reload” and “Equiped”
  • Made your animation or take free one, and put the animation id.

Animations must to be only arms movement for sure. The equip animation should be static, this is how your character will take the gun. You can also create another animation “Aim”, to make your character aiming, you will need to do a camera movement and change the fov localy.

Capture3

Step 4 [Create the configurations]

  • Create a new “Configuration” in the tool.
  • Create 3 new “Int Value” and 2 “Number Value” in the Configuration.
  • Rename the 3 Int Value “Ammo”, “Damage”, “Magazine”
  • Rename the 2 Number Value “Reload”, “Firerate”
  • Change these value to whatever you want.

You can also create some additional boolvalue, like “Automatic” to choose your gun mode, “VariousDamage” to do more or less damage (default damage 10 > VariousDamage random between 7 and 13 for example), “Aiming”, “reloading” ect…

Capture4

Step 5 [Create the events]

  • Create a new “Folder” in the tool, rename it “Events”
  • Create 2 new “Remote Event” rename them “Shoot” and “Reload”

Capture5

Step 6 [Create the bullet]

  • Create a new “Part” in the workspace, rename it “Bullet”
  • Resize it at (0.1, 0.1, 0.5), disable cast shadows, can collide and anchored.
  • Material = neon, Brick color = daisy orange (248, 217, 109), Transparency = 0.25
  • Create a new “Point Light” in the bullet.
  • Light color = (255, 255, 127), Brightness = 2.5, Range = 4
  • Create a new “Int Value”, rename it “Damage”
  • Create a new “String Value”, rename it “Player”
  • Put it in the Replicated Storage

Capture9

Final Step [Create the scripts]

  • Create a new “Folder” in the tool, rename it “Scripts”
  • Create a new “Script” in this folder, rename it “ServerHandler”
  • Create a new “Local Script” in this folder, rename it “Local Handler”
  • Create a new “Script” in the bullet, rename it “Casting”

Capture10

Scripting Part

Local Handler script

  • The first thing you can do here, it to get everything you will use into the script.
    Local Player = game.Players.LocalPlayer
    Local Weapon = script.Parent.Parent
    Local Sounds = Weapon:FindFirstChild(“Sounds”)
    ect…

  • Make sure to get the required service you need to use (User Input service, Player Mouse ect…)

  • Once you get everything, you can start by using a “Tool.Equipped” function to change the player mouse icon if needed, play the “Equip” sound, and change the player “ToolNone” animation by your “Equip” static animation.
    You can also start displaying your gun ScreenGui if you have one.

  • Then from here, you can use “User Input Service” to detect when you are pressing the reloading keybind, and use Mouse.Button1Down or Tool.Activated to shoot.

  • So while using these service, all you have to do is to play the animation and remote the required event related to the keybind or mouse button pressed. Don’t forget to add all required variable (player, sounds, values ect…)

  • For the end, Use “Tool.Unequipped” or “Tool.Removed” (don’t remember what’s the correct one xD) function, to remove the mouse icon and other things.

ServerHandler script

  • Here you’re getting the remote event.
  • So while reloading, play the reload sound, wait(Reload.Value) and change the Ammo.value to the Magazine.Value.
  • While shooting, play the fire sound, decrease the Bullet.Value by 1, clone the bullet and put it in workspace at your weapon barrel position, use a body velocity and Lookvector to move it or a TweenService for a smoother movement, change the bullet “Damage” value to the weapon “Damage” value, change the “Player” value to your player name, wait(Firerate.Value).

Don’t forget to verify if the Bullet.Value > 0 before to shoot and if the Bullet.Value < Magazine.Value before to reload (Do it in the local script too) ^^’

Casting script

  • Use a Raycasting or a magnitude function to detect enemies or walls parts.
  • While hiting, get the player and damage values, use the player value to do killfeed, hitmarker, hitsound, get the player team if needed ect… and use the damage value to do Humanoid:TakeDamage(Damage.Value), destroy the bullet.
  • While hiting a wall, you can create a part with a “decal” at the bullet position to do a bullet impact, and then destroy the bullet.
14 Likes

Thanks a lot man! I can only imagine how much time this took.

1 Like