Camera manipulation issue

I’m trying to make an event where a player’s camera moves to the CFrame of a part for a couple of seconds. The problem is, every script I’ve tried hasn’t worked and I’ve gotten nothing in the output with. I’ve tried to instance a camera and replace the current camera with that camera, and then place it to the CFrame of a part and focus it. I’ve tried to use the normal current camera in a local script, set it as scriptable and then edit it so that it could be moved. How would I approach this?

2 Likes

Try something like this.

local runService = game:GetService("RunService")

local camera = workspace.CurrentCamera

local part = -- Path to camera part

local function renderStepped()
    camera.CFrame = part.CFrame
end

local function cameraPart(seconds)
    camera.CameraType = Enum.CameraType.Scriptable
    
    local connection = runService.RenderStepped:Connect(renderStepped)
    
    task.wait(seconds)
    
    connection:Disconnect()
    
    camera.CameraType = Enum.CameraType.Custom
end

-- To start the camera part function
cameraPart(3) -- The parameter being however long until it returns to normal
2 Likes

You need to set the camera part to scriptable, not custom.

1 Like

I did. Look at the first line of the cameraPart function.

OP wants the camera to return to normal after a couple of seconds, so I disconnect the RunService connection and change the CameraType to Custom after x amount of seconds.

1 Like

Oh sorry, I was looking at the change after the disconnect.

2 Likes

I looked at a video from TheDevKing to understand more of what RunService was and I tried the script but the output said the part is an invalid member to workspace even though it’s in the workspace. I’ve had this issue before.

Try looking in the workspace during a test session to see if its actually there.

If so, try adding a :WaitForChild(), like this:

local part = workspace:WaitForChild("CamPartNameHere")
1 Like

Dang, it works, I think this is why I couldn’t do any of my previous scripts. Thanks!

1 Like

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.