Camera does not set


So i’m making titan shifting, and i spawn in fine the camera is locked like it should be, and then i spawn in the titan and someting happens, i am changing camera subject and i have a characteradded event that runs properly but for some reason does not set camera

What are you changing the camera subject to?

The character’s humanoid, as doing it to the other parts will likely result in weird offset

May I see the script covering this?

Yeah, gimme a sec, u need a pastebin or

Just anything is fine, whatever way you want to paste it.

1 Like
local call
script.Parent:WaitForChild('RemoteEvent').OnClientEvent:Connect(function()
    call = function()
        -- services:
        print('playeradded')
        local workspaceService = game:GetService("Workspace")
        local runService = game:GetService("RunService")
        local playersService = game:GetService("Players")
        local userInputService = game:GetService("UserInputService")
        userInputService. MouseIconEnabled = false
        -- config:
        local SENSITIVITY = 0.4
        local WORLD_OFFSET = Vector3.new(0, 2, 0)
        local LOCAL_OFFSET = Vector3.new(5, 1.75, 13)

        -- variables:
        local camera = workspaceService.CurrentCamera
        camera.CameraSubject = game.Players.LocalPlayer.Character:WaitForChild('Humanoid')
            local localPlayer = playersService.LocalPlayer
        local xAngle = 0
        local yAngle = 0
        local Type = game.Players.LocalPlayer:FindFirstChild('Class')
        Type:GetPropertyChangedSignal('Value'):Connect(function()
            if Type.Value == 'Titan' then
                print('Shifted')
                LOCAL_OFFSET = LOCAL_OFFSET + Vector3.new(0, 0, 25)
                task.wait(1)
                camera.CameraSubject = game.Players.LocalPlayer.Character.Humanoid
            else
                LOCAL_OFFSET = Vector3.new(5, 1.75, 13)
                task.wait(1)
                camera.CameraSubject = game.Players.LocalPlayer.Character.Humanoid
            end
        end)


        -- main:
        -- handle camera moving
        userInputService.InputChanged:Connect(function(input, isProcessed)
            -- validate input

            if isProcessed then return end
            if input.UserInputType ~= Enum.UserInputType.MouseMovement then return end
            -- get delta
            local delta = input.Delta
            local deltaX = delta.X
            local deltaY = delta.Y
            -- update angles
            xAngle = xAngle - deltaX * SENSITIVITY
            yAngle = math.clamp(yAngle - deltaY * SENSITIVITY, -80, 80)
        end)

        -- handle camera update
        runService:BindToRenderStep("CameraUpdate", Enum.RenderPriority.Camera.Value, function()
            -- get necessary data

            userInputService.MouseBehavior = Enum.MouseBehavior.LockCenter
            local cameraSubject = camera.CameraSubject
            if not cameraSubject then return end
            local isLocalPlayer = false
            local subject
            local ignoredInstance
            -- check camera subject class
            if cameraSubject:IsA("Humanoid") then
                ignoredInstance = cameraSubject.Parent
                if not ignoredInstance:IsA("Model") then return end
                subject = ignoredInstance.PrimaryPart
                if not subject then return end
                if localPlayer.Character == ignoredInstance and cameraSubject.Health > 0 then
                    isLocalPlayer = true
                end
            elseif cameraSubject:IsA("BasePart") then
                subject = cameraSubject
                ignoredInstance = cameraSubject
            else return end
            -- get positioned, world offset, and rotated cframe
            local xAngleCFrame = CFrame.Angles(0, math.rad(xAngle), 0)
            local anglesCFrame = xAngleCFrame:ToWorldSpace(CFrame.Angles(math.rad(yAngle), 0, 0))
            local cameraPosition = subject.Position + WORLD_OFFSET
            local startCFrame = CFrame.new(cameraPosition):ToWorldSpace(anglesCFrame)
            -- get camera focus and local offset cframe
            local cameraCFrame = startCFrame:ToWorldSpace(CFrame.new(LOCAL_OFFSET))
            local cameraFocus = cameraCFrame:ToWorldSpace(CFrame.new(0, 0, -LOCAL_OFFSET.Z))
            -- assign camera properties
            camera.Focus = cameraFocus
            camera.CFrame = cameraCFrame
            camera.CFrame = cameraCFrame:ToWorldSpace(CFrame.new(0, 0, -camera:GetLargestCutoffDistance({ignoredInstance})))

            -- rotate character
            if isLocalPlayer then

            end
        end)

        -- init
        userInputService.MouseBehavior = Enum.MouseBehavior.LockCenter
    
    end
    call()
    
end)
game.Players.LocalPlayer.CharacterAdded:Connect(function()
    call()
end)

i used a remote to change the subject, thanks @Ozxeb