Weapons Kit - Shoulder Camera

Okay, so I managed to fix it like this:

workspace.AR.Equipped:Connect(function()
	WeaponsSystem.camera:setEnabled(true)
end)
workspace.AR.Unequipped:Connect(function()
	WeaponsSystem.camera:setEnabled(false)
	workspace.CurrentCamera.CameraSubject = game.Players.LocalPlayer.Character.Humanoid
end)

replace workspace.AR to where your weapon is before you equip it
replace WeaponsSystem.camera:setEnabled(true) in the WeaponsSystem with the code I wrote.

6 Likes

Tell me if this doesn’t work, also this is a local script under the tool, and delete all camera stuff in that script. `
local Players = game:GetService(“Players”)
local ContextActionService = game:GetService(“ContextActionService”)
local UserInputService = game:GetService(“UserInputService”)
local RunService = game:GetService(“RunService”)

local camera = workspace.CurrentCamera
local cameraOffset = Vector3.new(2, 2, 8)
local player = Players.LocalPlayer

player.CharacterAdded:Connect(function()
game.Worksapce.Camera.CameraType = Custom
end)

script.Parent.Unequipped:Connect(function ()
game.Worksapce.Camera.CameraType = Custom
end)

script.Parent.Equipped:Connect(Function()
local character = script.Parent.Parent

local humanoid = character:WaitForChild("Humanoid")
local rootPart = character:WaitForChild("HumanoidRootPart")
humanoid.AutoRotate = false

local cameraAngleX = 0
local cameraAngleY = 0

local function playerInput(actionName, inputState, inputObject)
	-- Calculate camera/player rotation on input change
	if inputState == Enum.UserInputState.Change then
		cameraAngleX = cameraAngleX - inputObject.Delta.X
		-- Reduce vertical mouse/touch sensitivity and clamp vertical axis
		cameraAngleY = math.clamp(cameraAngleY-inputObject.Delta.Y*0.4, -75, 75)
		-- Rotate root part CFrame by X delta
		rootPart.CFrame = rootPart.CFrame * CFrame.Angles(0, math.rad(-inputObject.Delta.X), 0)
	end
end
ContextActionService:BindAction("PlayerInput", playerInput, false, Enum.UserInputType.MouseMovement, Enum.UserInputType.Touch)

RunService.RenderStepped:Connect(function()
	if camera.CameraType ~= Enum.CameraType.Scriptable then
		camera.CameraType = Enum.CameraType.Scriptable
	end
	local startCFrame = CFrame.new((rootPart.CFrame.Position)) * CFrame.Angles(0, math.rad(cameraAngleX), 0) * CFrame.Angles(math.rad(cameraAngleY), 0, 0)
	local cameraCFrame = startCFrame:ToWorldSpace(CFrame.new(cameraOffset.X, cameraOffset.Y, cameraOffset.Z))
	local cameraFocus = startCFrame:ToWorldSpace(CFrame.new(cameraOffset.X, cameraOffset.Y, -10000))
	camera.CFrame = CFrame.new(cameraCFrame.Position, cameraFocus.Position)
end)

end)

local function focusControl(actionName, inputState, inputObject)
– Lock and hide mouse icon on input began
if inputState == Enum.UserInputState.Begin then
UserInputService.MouseBehavior = Enum.MouseBehavior.LockCenter
UserInputService.MouseIconEnabled = false
ContextActionService:UnbindAction(“FocusControl”, focusControl, false, Enum.UserInputType.MouseButton1, Enum.UserInputType.Touch, Enum.UserInputType.Focus)
end
end
ContextActionService:BindAction(“FocusControl”, focusControl, false, Enum.UserInputType.MouseButton1, Enum.UserInputType.Touch, Enum.UserInputType.Focus)`

2 Likes

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!

34 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!

5 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