Check my original post "How Do I Change The Shoulder Camera Scripts In The "Auto Rifle" Model By Roblox To Change Plr Camera?" and check my second post "How Do I Change The Shoulder Camera Scripts In The "Auto Rifle" Model By Roblox Continuation?"
--Continuation 4
function ShoulderCamera:onCurrentCharacterChanged(character)
self.currentCharacter = character
if self.currentCharacter then
self.raycastIgnoreList[1] = self.currentCharacter
self.currentHumanoid = character:WaitForChild("Humanoid")
self.currentRootPart = character:WaitForChild("HumanoidRootPart")
self.rootRigAttach = self.currentRootPart:WaitForChild("RootRigAttachment")
self.rootJoint = character:WaitForChild("LowerTorso"):WaitForChild("Root")
self.currentWaist = character:WaitForChild("UpperTorso"):WaitForChild("Waist")
self.currentWrist = character:WaitForChild("RightHand"):WaitForChild("RightWrist")
self.wristAttach0 = character:WaitForChild("RightLowerArm"):WaitForChild("RightWristRigAttachment")
self.wristAttach1 = character:WaitForChild("RightHand"):WaitForChild("RightWristRigAttachment")
self.rightGripAttachment = character:WaitForChild("RightHand"):WaitForChild("RightGripAttachment")
self.currentTool = character:FindFirstChildOfClass("Tool")
self.eventConnections.humanoidDied = self.currentHumanoid.Died:Connect(function()
self.zoomedFromInput = false
self:updateZoomState()
end)
self.eventConnections.characterChildAdded = character.ChildAdded:Connect(function(child)
if child:IsA("Tool") then
self.currentTool = child
self:updateZoomState()
end
end)
self.eventConnections.characterChildRemoved = character.ChildRemoved:Connect(function(child)
if child:IsA("Tool") and self.currentTool == child then
self.currentTool = character:FindFirstChildOfClass("Tool")
self:updateZoomState()
end
end)
if Players.LocalPlayer then
local PlayerScripts = Players.LocalPlayer:FindFirstChild("PlayerScripts")
if PlayerScripts then
local PlayerModule = PlayerScripts:FindFirstChild("PlayerModule")
if PlayerModule then
self.controlModule = require(PlayerModule:FindFirstChild("ControlModule"))
end
end
end
else
if self.eventConnections.humanoidDied then
self.eventConnections.humanoidDied:Disconnect()
self.eventConnections.humanoidDied = nil
end
if self.eventConnections.characterChildAdded then
self.eventConnections.characterChildAdded:Disconnect()
self.eventConnections.characterChildAdded = nil
end
if self.eventConnections.characterChildRemoved then
self.eventConnections.characterChildRemoved:Disconnect()
self.eventConnections.characterChildRemoved = nil
end
self.currentTool = nil
self.currentHumanoid = nil
self.currentRootPart = nil
self.controlModule = nil
end
end
function ShoulderCamera:onCurrentCameraChanged(camera)
if self.currentCamera == camera then
return
end
self.currentCamera = camera
if self.currentCamera then
self.raycastIgnoreList[2] = self.currentCamera
if self.eventConnections.cameraTypeChanged then
self.eventConnections.cameraTypeChanged:Disconnect()
self.eventConnections.cameraTypeChanged = nil
end
self.eventConnections.cameraTypeChanged = self.currentCamera:GetPropertyChangedSignal("CameraType"):Connect(function()
if self.enabled then
self.currentCamera.CameraType = Enum.CameraType.Scriptable
end
end)
end
end
function ShoulderCamera:isHumanoidControllable()
if not self.currentHumanoid then
return false
end
local humanoidState = self.currentHumanoid:GetState()
return CONTROLLABLE_HUMANOID_STATES[humanoidState] == true
end
function ShoulderCamera:getCollisionRadius()
if not self.currentCamera then
return 0
end
local viewportSize = self.currentCamera.ViewportSize
local aspectRatio = viewportSize.X / viewportSize.Y
local fovRads = math.rad(self.fieldOfView)
local imageHeight = math.tan(fovRads) * math.abs(self.currentCamera.NearPlaneZ)
local imageWidth = imageHeight * aspectRatio
local cornerPos = Vector3.new(imageWidth, imageHeight, self.currentCamera.NearPlaneZ)
return cornerPos.Magnitude
end
function ShoulderCamera:penetrateCast(ray, ignoreList)
local tries = 0
local hitPart, hitPoint, hitNormal, hitMaterial = nil, ray.Origin + ray.Direction, Vector3.new(0, 1, 0), Enum.Material.Air
while tries < 50 do
tries = tries + 1
hitPart, hitPoint, hitNormal, hitMaterial = workspace:FindPartOnRayWithIgnoreList(ray, ignoreList, false, true)
if hitPart and not hitPart.CanCollide then
table.insert(ignoreList, hitPart)
else
break
end
end
return hitPart, hitPoint, hitNormal, hitMaterial
end
function ShoulderCamera:getRelativePitch()
if self.currentRootPart then
local pitchRotation = CFrame.Angles(self.pitch, 0, 0)
local relativeRotation = self.currentRootPart.CFrame:toObjectSpace(pitchRotation)
local relativeLook = relativeRotation.lookVector
local angle = math.asin(relativeLook.Y)
return math.clamp(angle, self.minPitch, self.maxPitch)
end
return self.pitch
end
function ShoulderCamera:getCurrentFieldOfView()
if self.zoomState then
return self.zoomedFOV
else
return self.fieldOfView
end
end
function ShoulderCamera:handlePartTransparencies()
local partsLookup = {}
local accoutrementsLookup = {}
for _, child in pairs(self.currentCharacter:GetChildren()) do
local hidden = false
if child:IsA("BasePart") then
hidden = partsLookup[child.Name] == true
child.LocalTransparencyModifier = hidden and 1 or 0
elseif child:IsA("Accoutrement") then
local descendants = child:GetDescendants()
local accoutrementParts = {}
for _, desc in pairs(descendants) do
if desc:IsA("Attachment") and accoutrementsLookup[desc.Name] then
hidden = true
elseif desc:IsA("BasePart") then
table.insert(accoutrementParts, desc)
end
end
for _, part in pairs(accoutrementParts) do
part.LocalTransparencyModifier = hidden and 1 or 0
end
elseif child:IsA("Tool") then
hidden = self.zoomState and (self.hasScope or self.hideToolWhileZoomed)
for _, part in pairs(child:GetDescendants()) do
if part:IsA("BasePart") then
part.LocalTransparencyModifier = hidden and 1 or 0
end
end
end
end
end

1 comment
check my post "How Do I Change The Shoulder Camera Script In The "Auto Rifle" Model By Roblox Continuation 3?" for the rest of the code