Another day, Another resource!
Today I’ve uploaded a very bare bones weapon switching system, as seen in practically every FPS game in existence.
Instructions
First things first, ungroup the folders into their respective places.
To switch weapons press the 1 key for primary and 2 key for secondary (If on controller, use button Y)
Adding tools
To add a new tool, first you want to name it to whatever you want. Then you will go to StarterCharacterScripts and find the String Value called “Primary” (or Secondary if you want) and rename it to the EXACT name you have for your tool. Then press 1 (or 2 if you used Secondary) and your tool should automatically equip.
Changing tool mid-game
Lets say you want to change the Secondary while the game is running. All you have to do in a script is change the value of Secondary to the name of the tool you want.
How it works
So basically, the player has 4 values onto their character. 2 bool values (true or false) and 2 string values. The local script checks if the button/key pressed is the 1 or 2 keys.
It also checks if the “EquippedPrimary” value equals false. If it is, it fires the remote event “EquipPrimary” with the values of the “Primary” (one of the string values), “EquippedPrimary” and “EquippedSecondary”. Then, the server script searches the “Guns” folder in ReplicatedStorage for a tool with the same name as the value of “Primary”. After that, it checks for if the gun is already in the player’s backpack. If so, it clones the tool found in the folder “Guns”, changes the values of “EquippedPrimary” to true and “EquippedSecondary” to false. Next, It puts the cloned tool into the player’s character, unequips any tools that are equipped, equips the cloned tool, and deletes the old gun. The same thing happens with switching to the secondary tool, just the values are different.
→ Model Link ←