Weapons Kit

*该内容即将支持你的所选语言。

To assist in creating competitive combat-based experiences, several endorsed weapons are available for use in any experience. The core system features projectile-based weapons with an over-the-shoulder camera, and setting the projectile speed high enough can simulate raycasting weapons like laser guns.

To use an endorsed weapon in your experience:

  1. Select a weapon from below, navigating to the asset library link.
Pistol
Shotgun
Auto Rifle
Submachine Gun
Sniper Rifle
Crossbow
Grenade Launcher
Rocket Launcher
Railgun
  1. On the weapon's item page, click the green Get button and confirm the transaction.

  2. In Studio, open the Toolbox (ViewToolbox).

  3. Select your toolbox Inventory section.

  4. Locate the weapon and click it to add it into the place. When prompted whether to put the tool into the starter pack, click Yes if you want players to start with the weapon in their backpack, or click No to simply place the weapon in the 3D world as a pickup.

  5. If this is the first time bringing in an endorsed weapon, move its WeaponsSystem folder into ServerScriptService to serve as the unified system folder for all endorsed weapons in the experience.

System Folder Structure

The WeaponsSystem folder is a unified folder that contains assets, configurations, and scripts that power all endorsed weapons in the experience. If located in ServerScriptService, it overrides any equivalent WeaponsSystem folders that may reside within individual weapons.

The WeaponsSystem folder contains the following instances:

Within the WeaponsSystem folder, different aspects are controlled by the following ModuleScripts:

AspectHandled Primarily Within...
Weapons Functionality
  • Libraries/BaseWeapon
  • WeaponTypes/BulletWeapon
  • WeaponTypes/BowWeapon
Shoulder Camera
  • Libraries/ShoulderCamera
Weapons GUI
  • Libraries/WeaponsGui
  • Libraries/DirectionalIndicatorGuiManager
  • Libraries/DamageBillboardHandler

Weapon Structure

Endorsed weapons are Tools and are named as they will appear in the player's backpack. Each weapon is structured with a similar hierarchy.

Weapon Type

The WeaponType StringValue corresponds with the ModuleScript for the weapon in the WeaponsSystem/WeaponTypes folder. The two base values are BulletWeapon and BowWeapon.

Weapon Model

Each weapon contains a Model made up of one or more BaseParts to form the physical weapon. One of these should be set as the model's PrimaryPart.

The model also includes the following important descendants which may be parented to one of the model's BaseParts:

  • TipAttachmentAttachment whose position on the parent BasePart determines where bullets/projectiles come out.
  • HandleAttachmentAttachment whose position on the parent BasePart determines where the Handle is welded.
  • Fired
    optional
    Sound that plays when the weapon is fired.
  • Reload
    optional
    Sound that plays when the weapon is reloaded.
  • Additional descendants for any specialized options.

Weapon Handle

The Handle part determines where a player character holds the weapon. This must be a Part, it must be named Handle, and it must be a direct child of the weapon (tool).

Configuration Folder

The Configuration folder contains specific "value" types for weapon behavior. Beyond the defaults, you can add additional configuration items for specialized options when applicable.

As follows are the base configurations and their default values:

ItemDescriptionDefault
AmmoCapacityNumber of shots in each "ammo clip" before player must reload. Note that ammo is unlimited and this does not specify how much ammo a player is carrying.30
FireModeChoose from either Semiautomatic (one shot per click/tap), Automatic (continuous fire), or Burst (burst of shots equal to NumBurstShots on each click/tap).Semiautomatic
ShotCooldownMinimum waiting time between clicks. For weapons with FireMode of Automatic, this is also the time between shots while pressing the fire button or holding click.0.1
BurstShotCooldownTime between each shot in a burst; only matters if you set FireMode to Burst.Value of ShotCooldown
NumBurstShotsNumber of shots per click/burst; only matters if you set FireMode to Burst.3
HitDamageAmount of damage each direct hit does.10
FullDamageDistanceMaximum distance that shots will do full damage. Anything hit beyond this distance will receive less and less damage as the distance nears ZeroDamageDistance.1000
ZeroDamageDistanceAnything hit at or beyond this distance will receive no damage.10000
BulletSpeedSpeed that bullets/projectiles travel when shot. Setting this to a very high value like 20000 simulates raycasting weapons like laser guns.1000
MaxDistanceMaximum distance bullets/projectiles travel before disappearing.2000
MinSpreadMinimum amount of spread for the weapon.0
MaxSpreadMaximum amount of spread for the weapon.Value of MinSpread
GravityFactorAmount that gravity should influence each bullet/projectile. For example, this value for the Crossbow is 1 because arrows arc during flight, but this value for the Rocket Launcher is 0 because propelled rockets travel straight.0
HasScopeSet to true if you want to use the scope that's specified in Weapons System GUI.false
ReloadAnimationName of the reload animation track in Assets/Animations of the system folder.RifleReload
AimTrackName of the aim animation track in Assets/Animations of the system folder.RifleAim
AimZoomTrackName of the aim zooming animation track in Assets/Animations of the system folder.RifleAimDownSights
RecoilMinMinimum recoil added for each shot.0.05
RecoilMaxMaximum recoil added for each shot.0.5
TotalRecoilMaxTotal maximum accumulated recoil. Weapon's current recoil will never exceed this value.2
RecoilDecayDecay multiplier for recoil; essentially the rate at which recoil diminishes after shooting.0.825
RecoilDelayTimeWaiting time after shooting/clicking before recoil is added to camera.0.07
StartupTimeLength of time after equipping the weapon before the player can shoot. This prevents players from firing a single shot from multiple different weapons in quick succession.0.2
FiredPlaybackSpeedRangeAmount that the pitch can vary for the Fired sound of the weapon. Set this to 0 to always play it at the same pitch.0.1
NumProjectilesNumber of bullets/projectiles that will fire at the same time when you click/tap once. This is useful for weapons like the Shotgun that fires multiple bullets at same time. Note that one shot will always use exactly one ammo regardless of this value.1

Specialized Options

You can add/modify the following options for any weapon. These customizations require modifying either the weapon's Model, the weapon's Configuration, or both. Some configurations are dependent on others, such as Muzzle Particles which require the necessary children for Projectile/Hit Effects and Sounds.

Bolt Animations and Sounds

A weapon's bolt is the part that moves back and forth each time it's fired.

BoltBasePart that moves when the weapon is fired.
BoltMotorMotor6D used to animate the bolt. Make sure to set the motor's Part0 to the weapon model's PrimaryPart and Part1 to the Bolt part.
BoltMotorStartAttachment whose position on the parent BasePart determines where the bolt is when it's at rest.
BoltMotorTargetAttachment whose position on the parent BasePart determines where the bolt animates to when shooting.
BoltOpenSoundSound that plays when the bolt opens.
optional
BoltCloseSoundSound that plays when the bolt closes.
optional
ItemDescriptionDefault
ActionOpenTimeTime it takes for the bolt to animate to open position.0.025
ActionCloseTimeTime it takes for the bolt to animate to closed position.0.075

Ejecting Bullet Casings

Weapons can include physical bullet casings that eject upon firing and fall to the ground.

CasingEjectPointAttachment whose position on the parent BasePart determines where you want bullet casings to pop out. Note that its orientation determines the direction that casings pop out.
ItemDescriptionDefault
CasingEffectName of casing BasePart in Assets/Effects/Casings of the system folder.
CasingEjectSpeedMinMinimum eject speed of casings15
CasingEjectSpeedMaxMaximum eject speed of casings18
CasingHitSoundSound that plays when casings hit the ground.
optional

Projectile/Hit Effects and Sounds

You can configure physical projectiles for any weapon, along with Sounds, Beams, and ParticleEmitters for hit effects and other special effects.

ItemDescriptionDefault
ShotEffectName of a shot effect stored within Assets/Effects/Shots of the system folder.
ShouldMovePartSet to true if the weapon's ShotEffect should move with the projectile or false if not. You should only set this to true if there's a visible object that moves with each shot, such as an arrow or rocket.false
BeamFadeTimeTime it takes for Beam0 or Beam1 (see below) to fade after the bullet/projectile hits something. By default, no manual fade will be applied by code.0
BeamWidth0Thickness of Beam0 or Beam1 at Attachment0 (see below).1.5
BeamWidth1Thickness of Beam0 or Beam1 at Attachment1 (see below).1.8
NumHitParticlesNumber of particles the HitParticles (see below) emitter will emit.3
HitParticlesUsePartColorSet to true if you want the hit particles to be the color of the hit surface; false if you want hit particles to not change color.true
  • Descendants of the specified ShotEffect noted in the previous section
FlyingSound that plays while the bullet/projectile is traveling.
optional
Beam0First slot for a trailing Beam behind the bullet/projectile. Don't forget to set Attachment0 and Attachment1.
optional
Beam1Second slot for a trailing Beam behind the bullet/projectile. Don't forget to set Attachment0 and Attachment1.
optional
Attachment0Attachment whose position on the parent BasePart determines the back of trailing beams; make sure to set Beam.Attachment0 on both Beam0 and Beam1 to this.
optional
Attachment1Attachment whose position on the parent BasePart determines the front of trailing beams; make sure to set Beam.Attachment1 on both Beam0 and Beam1 to this.
optional
TrailParticlesParticleEmitter parented as a direct child of Attachment0; this will emit while the bullet/projectile is traveling.
optional
LeadingParticlesParticleEmitter parented as a direct child of Attachment1; this will emit while the bullet/projectile is traveling.
optional
HitEffectAttachment whose position will be set to Beam.Attachment1 of Beam0 when the bullet/projectile hits. You must specify Beam0 and its attachments for this to work properly.
optional
HitSoundSound parented as a direct child of HitEffect; plays when the bullet/projectile hits.
optional
HitParticlesSound parented as a direct child of HitEffect; emits when the bullet/projectile hits.
optional
[ProjectilePart]Any Part or MeshPart that you want to appear as a physical projectile. Make sure you set ShouldMovePart noted in the previous section to true if you have a visible object here.
optional

Muzzle Particles

This option emits particles from the specified ParticleEmitter at the weapon's TipAttachment Attachment when it's fired.

Configuration descendants:

  • ShotEffect (StringValue) — Name of a shot effect stored within WeaponsSystem/Assets/Effects/Shots.
  • NumMuzzleParticles (IntValue) (optional) — Number of muzzle particles that will be emitted; default is 50.

For the specified shot effect, add a ParticleEmitter asset within WeaponsSystem/Assets/Effects/Shots named MuzzleParticles.

Muzzle Flashes

This option creates a Beam flash effect when the weapon is fired.

Model descendants:

  • MuzzleFlash0 (Attachment) — Used to specify one side of muzzle flash. Position doesn't matter.
  • MuzzleFlash1 (Attachment) — Used to specify opposite side of muzzle flash. Position doesn't matter.
  • MuzzleFlash (Beam) — Make sure to set Attachment0 to MuzzleFlash0 and Attachment1 to MuzzleFlash1.

Configuration descendants:

  • MuzzleFlashTime (NumberValue) (optional) — Length of time muzzle flash will show for; default is 0.03.
  • MuzzleFlashRotation0 (NumberValue) (optional) — Minimum rotation of muzzle flash; default is -math.pi.
  • MuzzleFlashRotation1 (NumberValue) (optional) — Maximum rotation of muzzle flash; default is math.pi.
  • MuzzleFlashSize0 (NumberValue) (optional) — Minimum size of muzzle flash; default is 1.
  • MuzzleFlashSize1 (NumberValue) (optional) — Maximum size of muzzle flash; default is 1.

Particle Trails

This option creates a trail of varying length from the weapon to the projectile impact point.

Configuration descendants:

  • TrailLength (NumberValue) (optional) — Length of trail behind bullet/projectile; default is nil which means the trail length will instead be calculated using TrailLengthFactor.
  • TrailLengthFactor (NumberValue) (optional) — The trail length will be set to this value multiplied by the distance the bullet/projectile traveled in the last frame; default is 1. Note that this will be overridden if you include TrailLength.
  • ShowEntireTrailUntilHit (BoolValue) (optional) — Set to true to render the trail from the weapon tip all the way to wherever the projectile is; this will override both TrailLength and TrailLengthFactor and the trail will only disappear once the projectile hits something. Set to false to use one of the above two options to calculate trail length. Default is false.

Hit Marks

This visual addition appears on the surface where projectiles hit and is useful for arrows, bullet holes, scorch marks, etc.

Configuration descendants:

  • HitMarkEffect (StringValue) (optional) — Name of hit mark effect stored within WeaponsSystem/Assets/Effects/HitMarks; default is BulletHole.
  • AlignHitMarkToNormal (BoolValue) (optional) — Set to true if the hit mark should always align flat against the surface like a bullet hole, or false if the hit mark should appear stuck in the surface from the direction the projectile came from (like an arrow). Default is true.

You can add the following optional asset within WeaponsSystem/Assets/Effects/HitMarks:

  • Glow (Decal) (optional) — Appears on the hit surface fully opaque, then rapidly gets more transparent, like a glowing effect on the surface that fades quickly. Useful for things like showing a glowing red mark where explosives hit.
  • BulletHole (Decal) (optional) — Appears on the hit surface fully opaque and, after 4 seconds, fades to transparent over 1 second.
  • ImpactBillboard (BillboardGui) (optional) — Displays at the hit surface, always facing towards the camera.
    • Impact (ImageLabel) (optional) — Direct child of ImpactBillboard; this begins fully opaque, grows to the full size of the ImpactBillboard over 0.1 seconds, then shrinks to half its size and fades to full transparency over 0.1 seconds.
  • Any Part/MeshPart/SpecialMesh that you want to appear as a physical projectile (optional). For example, including an arrow MeshPart and setting AlignHitMarkToNormal noted above to false will make the arrow stick out of the surface from the direction you shot it.

Exploding Projectiles

Projectiles can include an Explosion object to damage player characters in an area around the impact point.

Configuration descendants:

  • ExplodeOnImpact (BoolValue) (optional) — Set to true if you want bullets/projectiles for the weapon to explode on impact, false otherwise. Default is false.
  • BlastRadius (NumberValue) (optional) — BlastRadius of explosion; default is 8.
  • BlastPressure (NumberValue) (optional) — BlastPressure of explosion; default is 10000.
  • BlastDamage (NumberValue) (optional) — Damage dealt to things in the center of the explosion. Note that the explosion does less damage the farther away hit objects are from the center of the explosion. Default is 100.

Charging Weapon

A charging weapon like the Railgun must be charged up between shots before it can fire again.

Model descendants:

  • Charging (Sound) (optional) — Plays while the weapon is charging.
  • Discharging (Sound) (optional) — Plays while the weapon is discharging, for example if you charge the weapon just partially and release the shoot button.
  • ChargeComplete (Sound) (optional) — Plays when the weapon has reached full charge.
  • DischargeComplete (Sound) (optional) — Plays when the weapon has completely discharged.
  • ChargeGlow (BasePart) (optional) — This object will get less transparent as the weapon charges up, such that it will be fully opaque at 100% charge.
  • ChargeCompleteParticles (ParticleEmitter) (optional) — Emits when the weapon has finished charging. This emitter can be a child of any model BasePart or a child of an Attachment within the BasePart.
  • DischargeCompleteParticles (ParticleEmitter) (optional) — Emits when the weapon has completely discharged. This emitter can be a child of any model BasePart or a child of an Attachment within the BasePart.
  • ChargingParticles (ParticleEmitter) (optional) — Emits while the weapon is charging. You can include multiple emitters of this name and each will emit while charging. This emitter can be a child of any model BasePart or a child of an Attachment within the BasePart.

Configuration descendants:

  • ChargeRate (NumberValue) — Rate at which the weapon will charge. This value must be specified to indicate that the weapon uses charging.
  • DischargeRate (NumberValue) (optional) — Rate at which the weapon will discharge; default is 0 which means the weapon will not discharge at all.
  • ChargePassively (BoolValue) (optional) — Set to true if you want the weapon to passively charge so it will shoot instantly when you click, or false if you want to click/touch to charge the weapon and have it fire once full charge is reached. Default is false.
  • ChargingParticlesRatePerCharge (IntValue) (optional) — Number of particles that will emit out of all ChargingParticles emitters multiplied by the current charge of the weapon. Default is 20, meaning that if the weapon charge is at 10%, each ChargingParticles emitter will emit 2 particles (20×0.1), and if the weapon charge is at 90%, each emitter will emit 18 particles (20×0.9).
  • FireDischarge (NumberValue) (optional) — Amount of charge the weapon will lose after firing a fully charged shot; default is 1.
  • NumChargeCompleteParticles (IntValue) (optional) — Number of particles the - ChargeCompleteParticles emitter will emit once the weapon is fully charged. Default is 25.
  • NumDischargeCompleteParticles (IntValue) (optional) — Number of particles the - DischargeCompleteParticles emitter will emit when the weapon is completely discharged. Default is 25.

Bow Weapon

A bow weapon like the Crossbow can include a realistic string and arms construction, as well as a visual arrow nocked to the string.

In addition to adding model descendants, you need to apply the following:

  • Make the weapon into a charging weapon. For example, add the required ChargeRate within the weapon's Configuration that specifies how fast the string is drawn. Additionally, consider adding optional descendants to the weapon's Model such as a Charging sound for the string/arms being pulled back.
  • Set the WeaponType to BowWeapon as indicated in Weapon Structure.

Model descendants:

  • LeftString (Beam) (optional) — The visual left half of the string.
  • RightString (Beam) (optional) — The visual right half of the string.
  • Arrow (BasePart) (optional) — The arrow that appears when the bow is fully drawn. Note that this is only for visual appearance on the bow (the actual fired arrow will be a ShotEffect as outlined in Projectile/Hit Effects and Sounds).
  • String1 (Attachment) (optional) — The center point of the string.
  • StringLoose (Attachment) (optional) — Point where String1 should be when the bow is at rest.
  • StringTight (Attachment) (optional) — Point where String1 should be when the bow is fully drawn.
  • Arms (Part) (optional) — A part that just serves as an internal indicator that the bow arms will be animated. This may contain the following direct children:
  • LeftString0 (Attachment) (optional) — Point where the left side of the string is attached to the bow.
  • RightString0 (Attachment) (optional) — Point where the right side of the string is attached to the bow.
  • LeftLoose (Attachment) (optional) — Point where LeftString0 should be when the bow is at rest.
  • RightLoose (Attachment) (optional) — Point where RightString0 should be when the bow is at rest.
  • LeftTight (Attachment) (optional) — Point where LeftString0 should be when the bow is fully drawn.
  • RightTight (Attachment) (optional) — Point where RightString0 should be when the bow is fully drawn.
  • [SpecialMesh] (SpecialMesh) (optional) — The part of the bow that will actually bend when the bow is drawn. Note that you must specify the following four Vector3Value objects to make this animate.
  • LooseOffset (Vector3Value) (optional) — Offset of the SpecialMesh when the bow is at rest.
  • TightOffset (Vector3Value) (optional) — Offset of the SpecialMesh when the bow is fully drawn.
  • LooseScale (Vector3Value) (optional) — Scale of the SpecialMesh when the bow is at rest.
  • TightScale (Vector3Value) (optional) — Scale of the SpecialMesh when the bow is fully drawn.

Weapons System GUI

The core weapons system interfaces with this system to update the GUI based on things like spread of the gun, indicators for when you get hit or hit others, etc.

The WeaponsSystemGui is a ScreenGui object in WeaponsSystem/Assets that is parented to PlayerGui when the experience starts. WeaponSystemGui has 4 descendants:

Scaling Elements

ScalingElements is a Folder parented under WeaponsSystemGui with the following descendants:

NameInstance TypeDescription
DirectionalIndicatorsFolderA Folder where all directional indicators are stored.
CrosshairFrameA Frame containing the following objects:

[UIAspectRationConstraint] - UIAspectRatioConstraint
Bottom - ImageLabel
Left - ImageLabel
Right - ImageLabel
Top - ImageLabel
HitMarkerFrameA Frame containing the following objects:

[UIAspectRatioConstraint] - UIAspectRatioConstraint
HitMarkerImage - ImageLabel that appears and fades when the player successfully hits another player character.

LargeTouchscreen

LargeTouchscreen is a Frame containing buttons that display on large touchscreens. LargeTouchscreen has the following descendants:

Scope

Scope is a Frame that contains ScopeImage (ImageLabel) which shows up when zooming on a weapon with HasScope enabled (see Weapon Structure).

Scope has the following descendants:

NameInstance TypeDescription
ScopeInstanceFrameA Frame containing the following assets used when zooming on a weapon with HasScope enabled:

[UIAspectRationConstraint] - UIAspectRatioConstraint
BottomBlack - Frame
LeftBlack - Frame
RightBlack - Frame
TopBlack - Frame

SmallTouchscreen

SmallTouchScreen is a Frame containing buttons that display on small touchscreens. SmallTouchscreen has the following descendants:

Create a Directional Indicator

Directional indicators are used to show the direction of something around the player's crosshair. For example, if someone shoots you, a red semi-circle can show up around your crosshair in the direction the shot came from. Other examples include indicators to show the direction of footsteps, indirect gunfire, or even environmental objects such as chests.

To create a new indicator, add a new Indicator Frame in WeaponsSystemGui/ScalingElements/DirectionalIndicators with the following structure:

NameInstance TypeDescription
[UIAspectRationConstraint] UIAspectRatioConstraint
[ImageLabel]ImageLabelImage of the directional indicator. Tweaking the rotation of the image in Studio may be required unless you upload the image so that it's facing down and there's little or no blank space around it.
This image label must also contain its own
UIAspectRatioConstraint.
[Configuration]ConfigurationContains optional properties to adjust. See Indicator Configuration for more information.

Once created, you can activate an indicator via the following command inside WeaponsSystem/Libraries/WeaponsGui where indicatorName is the string name of the indicator to activate and worldPos is the world position where the directional indicator should point:


self.DirectionalIndicatorGuiManager:ActivateDirectionalIndicator(indicatorName, worldPos)

Indicator Configuration

The DirectionalIndicators can be further modified by adjusting the Configuration object parented under the [Indicator]. All of these settings have a default value, so there is no need to set configurations when not modifying a setting.

The following configurations can be set:

NameInstance TypeDescription
DistanceLevelFromCenterNumberValueNumber of distance levels from the center of the screen (each distance level is about 0.03 screen scale); default is 6.
FadeTimeNumberValueIndicator fade time following its activation and the TimeBeforeFade time; default is 1.
NameStringValueName of the directional indicator as you want to reference it in code; default is the name of the indicator's top level Frame.
TimeBeforeFadeNumberValueNumber of seconds that the indicator will appear for before fading; default is 1.
TransparencyBeforeFadeNumberValueTransparency of the indicator before it starts to fade; default is 0.
WidthLevelNumberValueNumber of width levels from center (each width level is about 0.03 screen scale); default is the value of DistanceLevelFromCenter.

Show Damage Billboard

The damage billboard is used to show little numbers above a character's head when they are damaged. These will only show up for the player that damaged another player's character, not for spectating players.

Damage billboards are handled in WeaponsSystem/Libraries/DamageBillboardHandler and can be activated from any client-side code as follows, where damage is the amount of damage done and adornmentPart is the part on which to adorn the billboard, such as the victim's head:


DamageBillboardHandler:ShowDamageBillboard(damage, adornmentPart)

Shoulder Camera

The shoulder camera is a third-person camera that looks over the player character's right shoulder. To customize the shoulder camera, modify the variables under the -- Configuration parameters (constants) comment in the ShoulderCamera.new() function of WeaponsSystem/Libraries/ShoulderCamera. You can modify things such as field of view, offset from the character, walk speed while sprinting or zooming, etc.

Sprint and Zoom Control

By default, the weapons system adds "sprint" capability, so players can sprint by holding the Shift key, pushing fully up on the dynamic thumbstick (mobile), or pushing fully up on the left joystick (gamepad). If you want to disable sprinting, set the value of SprintEnabled within WeaponsSystem/Configuration to false.

The system also reduces player speed while they're aiming/zooming, but you can disable this behavior by setting the value of SlowZoomWalkEnabled to false.