Weapons Kit - Shoulder Camera

The text glitched out, and also that over the shoulder camera was from the Roblox Developer website.

1 Like

I don’t think that code is needed, didn’t he mean that when he equips the tool, the camera should change and when he unequips it, it changes back? My code works completely fine, and it’s not very long, the only thing that needs to happen is to set the camera back to normal, so, the only needed things are to set the camera Enabled to false, and to return the camera subject to it’s original object, the humanoid

1 Like

My gun isn’t in workspace though; it’s saved in ServerStorage and given to certain players when the round starts. Is there a built in way to access the tool itself? I’m looking through the WeaponsSystem script and I don’t see anything but I’m completely new with this system.

Edit: Upon testing I found out that the folder the script is in is moved to ReplicatedStorage which makes accessing the tool even harder lol

3 Likes

Fixed it! I accomplished what I wanted by adding the following line of code to line 397:
WeaponsSystem.camera:setEnabled(hasWeapon)

So that entire block looks like this:

if WeaponsSystem.gui then
		WeaponsSystem.gui:setEnabled(hasWeapon)
		WeaponsSystem.camera:setEnabled(hasWeapon)

(Seems hacky but it works)

The only problem is when it gets disabled the camera is slightly lower than it should be :confused:

Edit: I found out through testing that if the player dies, it’ll fix the camera, which means I should be able to use this from here without any problems. In the event that I want to remove guns, though, a fix to this would be cool.

Edit 2: Fixed that as well! Fixed it by adding the following to line 276.
self.currentCamera.CameraSubject = self.currentHumanoid
So the entire block looks like this:

if self.currentCamera then
	self.currentCamera.CameraType = Enum.CameraType.Custom
	self.currentCamera.CameraSubject = self.currentHumanoid
end

Thanks to @LightningLion58 and @gamerobotjimmy for your help!

35 Likes

Glad it works for you! To fix the lower camera, change the camera’s subject back to the humanoid! That’s included in the solution I sent you, do

 workspace.CurrentCamera.CameraSubject = Player.Character.Humanoid

that will fix the lower camera.
NVM, didn’t read the second edit, glad it works!

4 Likes

I am also using the same system and I needed the camera to not be toggled on when you’re not holding the gun so I tried using your code. However, it did not work.
I believe it was because I didn’t do it correctly on line 397.

What line 397 looks on my non edited shoulder camera script is below.

local cameraCFrameInSubjectSpace =
		cameraYawRotationAndXOffset *
		pitchRotation * 	-- rotate around the X axis (look up/down)
		yOffset *			-- move camera up/vertically
		zOffset				-- move camera back
	self.currentCFrame = rootPartUnrotatedCFrame * cameraCFrameInSubjectSpace
9 Likes

Thanks, man - You’re a lifesaver!!

This script is also incorporated in the Roblox Crossbow set, which I like. For some reason, they enable it whether it’s equipped or not, and never turn it off when it’s unequipped, causing it to break your mouse and game.

To fix it - I disabled the initial execution of the WeaponsSystem script on ~Line 185-190
WeaponsSystem.camera:setEnabled(true). Then replace the lines you provided above.

The self.currentCamera.CameraType = Enum.CameraType.Custom is located in the Libraries > ShoulderCamera ModuleScript on ~Line 275

:+1: :+1:

6 Likes

Awesome! It seems like the weapons kit has been modified since this post was made, and I’ve been unable to fix it since. Do you think you could send an .rbxl file of the modified Weapons System folder? That’d be extremely useful for me, thanks!

6 Likes

No problem.

I needed a Crossbow. So, here is the Weapons System using Roblox’s Crossbow model and scripts…WeaponsSystem_crossbow.rbxl (108.8 KB)

6 Likes

So I used this to fixed the shoulder cam on the auto rifle using the script provided but when a different player equips a gun all players get the shoulder cam. How would I go about fixing this?

2 Likes

It’s probably because the WeaponSystem stuff is replicated to all client’s ReplicatedStorage. That’s why they all change to Shoulder Cam.

2 Likes

So what should I do? to fix this and only make the shouldercam go to a single client?

3 Likes

Found a issue when using the modified script. When unequiping the crossbow (to std camera), whilst moving, the player character tilts 7 to 8 degrees on the heels (client side). Looks bad. Anyway, effectively hollowing or emptying (commenting out) this function in the shoulder camera script as follows (~ line 488), stops this:

function ShoulderCamera:applyRootJointFix()
if self.rootJoint then
–local translationScale = self.zoomState and Vector3.new(0.25, 0.25, 0.25) or Vector3.new(0.5, 0.5, 0.5)
–local rotationScale = self.zoomState and 0.15 or 0.2
–local rootRotation = self.rootJoint.Part0.CFrame - self.rootJoint.Part0.CFrame.Position
–local rotation = self.rootJoint.Transform - self.rootJoint.Transform.Position
–local yawRotation = CFrame.Angles(0, self.yaw, 0)
–local leadRotation = rootRotation:toObjectSpace(yawRotation)
–local rotationFix = self.rootRigAttach.CFrame
–if self:isHumanoidControllable() then
– rotationFix = self.rootJoint.Transform:inverse() * leadRotation * rotation:Lerp(CFrame.new(), 1 - rotationScale) + (self.rootJoint.Transform.Position * translationScale)
–end

	--self.rootJoint.C0 = CFrame.new(self.rootJoint.C0.Position, self.rootJoint.C0.Position + rotationFix.LookVector.Unit)
end

end

– This function keeps the held weapon from bouncing up and down too much when you move. For me, its okay without it and way better than having the player character become tilted.

5 Likes

Tried for hours to sort this and using a new copy on seeing this thread, The WeaponSystem still must be in the StarterPack directory for my weapons to work right now and that was without any edits.

Players cannot use shift though and I get this in Output…

21:12:54.283 - ActivateCameraController did not select a module. (x2)

Does anyone else need to keep the WeaponsSystem in a weapon for the weapons to work despite no instructions to do so?

2 Likes

Used ‘papa_kupcake’s’ modified script (several posts above), for the crosbow. Found this varient to work in the starterpack or as I am using it, dispensed on purchasing in game. Where it then copies many of the modular scripts to replicated storage. As I recall Robox page on its weapon kit/s talks about placing most of the scripts directly into replicated storage. However this did not work for this crossbow script when I tried it, and have not noticed any problems, with it coping itself into position post launch for mulitple players.

2 Likes

Thanks for this @papa_kupcake it works nicely and I’m now eager to figure out what you did.

Are all the changes you made mentioned above?

I need to update my own branch of the WeaponsSystem which logs damage history for issuing rewards fairly.

2 Likes

Yes, the changes I made are mentioned above, as well as the cause of it being broken. @Thundermaker300 actually provided the main fixes. I simply applied them to Roblox’s updated Weapons System.

3 Likes

Hello, which lines will I have to change? Please show me exactly what you changed! :hugs:

2 Likes

See the 1st reply-post that I made above. I mention what I changed.

1 Like

A fellow programmer (@AstralKingdoms) and I fixed the weapons system up a bit. See below for how to add our fix and what we changed.

  1. Place the modified WeaponsSystem in ReplicatedStorage: WeaponsSystem.rbxm (90.0 KB)
  2. Add any of the desired weapons from the original kit (list on the Weapons Kit hub page)
  3. Once the weapon is added, delete the WeaponsSystem that comes with it, as well as any scripts inside of it (don’t delete anything else).
  4. Add the following script directly inside the tool object: ServerWeaponsScript.rbxm (1.7 KB)
  5. Configure and give the weapons out as desired.

This weapons system fixes the following issues outlined in this post:

  • Shoulder script only applies while the gun is equipped (will force stop it when the gun is unequipped)
  • Camera will not break upon unequipping the tool.

There are still some bugs with it, including…

  • If the tool is deleted from the character model, the shoulder camera will be stuck until a different weapon is equipped, and the animation will be stuck until the character is reloaded. To fix this, just call Humanoid:UnequipTools() and wait a frame before deleting it.
  • If the user unequips the tool (either manually or via :UnequipTools()) while they are scoped in, their walkspeed will remain the scope walking speed (which is slower than the default 16 walking speed). This bug wasn’t discussed in this post, but I discovered it on my own.
36 Likes