Before we start, we’re gonna explain some thing’s so a noob scripter can understand this.
In this part we will be setting up the framework.
For noob scripters:
CFrame
What is a CFrame?
CFrame are like Position and Orientation into one mess, they act like a Vector3 but are not compatible when there raw.
More information is here: Comprehensive Beginner's Guide to CFrames and How to Use Them [CFrame Guide]
Raycasting
Raycasting is something that cast’s a ray in a certain distance (studs) to give you whatever it hits.
Imagine a part that moves until it hits something and whatever it hits you get the information of that thing that the part hits, that’s raycasting simply.
But there’s more! You have to give that part information (Origin, Distance and Direction) in order for the part to move.
More information: My Intro to Raycasting - WHAT, WHY, and HOW
Now on to the juicy part!
Main part:
Creating the models
This should be simple for you.
We need a viewmodel which is a pair of arms and even sometimes a gun model included.
Now I provided a viewmodel so you don’t have to waste time making one or just get one on the Toolbox.
coolViewModel.rbxm (12.1 KB)
Make your own animations or the preset ones and after your done making the animations or publishing the preset one’s replace the AnimationId on the Idle animation Instance (Found in AnimationController).
Now create a folder in ReplicatedStorage called Weapons and put the viewmodel there.
Scripting the weapon settings
Create a module script in the viewmodel called Settings.
Here’s a template for now:
local settingsModule = {}
settingsModule.Name = "Weapon name here"
settingsModule.AmmoMax = 10
settingsModule.RecoilWait = 0.03
return settingsModule
settingsModule.Name
is used for GUI which is a another thing for Part 2 or 3.
settingsModule.AmmoMax
is used for reloading (e.g Shooting but then there’s no more ammo left, in order to check we need settingsModule.AmmoMax
).
settingsModule.RecoilWait
is used for waiting after each recoil so you can’t spam shooting.
End:
Summary
Good job! You successfully made the setup for the framework!
Next part we will script the viewmodel so it can follow the camera and do animations!
If your looking to tell me feedback about how I can change some things about this post then tell me with “PostFeedback:” at the start.