Gun Package disables sprinting under certain conditions

Describe the bug:

I’ve identified the bug with the gunScript and the inability to sprint.

When you equip a gun, the first thing it does is set an internal instance variable self.attachedToSprintablePlayer to the current value of player.canSprint .

player.canSprint is modified by guns in the following situations:

  1. If the property canSprintWhileInUse is false, and the user is firing the gun, canSprint will be set to false
  2. When the player stops firing, and canSprintWhileInUse is false, canSprint will be set to self.attachedToSprintablePlayer
  3. If the property canSprintWhileInUse is false, and the player reloads, canSprint will be set to false
  4. In all cases, when the player finishes reloading, canSprint is set to canSprintWhileInUse

Ergo, if you switch weapons while reloading or firing, then the self.attachedToSprintablePlayer instance variable will erroneously be false, and you won’t be able to sprint.

To fix this, add an OnDestroy method to the GunScript to restore the sprinting state before the new gun is equipped.

function GunScript:OnDestroy()
  self:GetEntity():GetParent().canSprint = self.attachedToSprintablePlayer
end

Which platform: PC / Stadia

Which input: Controller / keyboard + mouse

Your Crayta username: Cereal

Game seen in (including “Hub” or “Editor for XYZ”): Gun Package

How regularly do you see this? (E.g. 2/3 times - please try 3 times if possible): Easily reproducible

Time + date seen: March 05 2022

Version number (found in Help tab in Settings): 0.e5.40.115857

3 Likes