Camera not locking to a part's location

I was working on a main menu scene but this code will not work. It is supposed to lock the camera in the location of a part. I have tried debugging it, but no luck. :frowning: This is a local script inside startergui. What am I doing wrong?

    local Player = game.Players.LocalPlayer
    local Character = Player.Character
    local Camera = workspace.CurrentCamera

    repeat wait()
    Camera.CameraType = "Scriptable"
    until Camera.CameraType == "Scriptable"

    Camera.CFrame = workspace.Main_Menu_Scene.CamIntro.Position

    if Camera.CFrame == not workspace.Main_Menu_Scene.CamIntro.Position then
    warn("ERROR")
    end

Try Camera.CFrame = workspace.Main_Menu_Scene.CamIntro.CFrame instead, since the Cameras CFrame must be, well, a CFrame.

local Player = game.Players.LocalPlayer
local Character = Player.Character
local Camera = workspace.CurrentCamera

repeat wait()
Camera.CameraType = "Scriptable"
until Camera.CameraType == "Scriptable"

Camera.CFrame = workspace.Main_Menu_Scene.CamIntro.CFrame

if Camera.CFrame ~= workspace.Main_Menu_Scene.CamIntro.CFrame then
warn("ERROR")
end

You were trying to set the camera’s CFrame to a Vector3 and not a CFrame. You also need to use ~= to compare the two CFrames in this situation.

Still doesn’t work. No errors in the output.

Also, when I play the game the camera is stuck a couple feet above the player, not in the position I set.

Perhaps you could try creating a CFrame with the Vector3 of the Position?

local newCframe = CFrame.new(workspace.Main_Menu_Scene.CamIntro.Position)
Camera.CFrame = newCframe

if Camera.CFrame ~= newCframe then
warn("ERROR")
end

doesn’t work. I get the same result as before.

Well depending on when your code runs, it be may have an affect on the outcome based on the indexing. I notice you seem to be using a LocalScript. It is almost always good practice to index with the WaitForChild() event, to ensure that the path is available for execution. You can try this: workspace:WaitForChild("Main_Menu_Scene"):WaitForChild("CamIntro").Position
or
workspace:WaitForChild("Main_Menu_Scene"):WaitForChild("CamIntro").CFrame

It still doesn’t work. :frowning:

Ah, you could try setting the Camera.CameraSubject to the CamIntro part.

This would not work, because the cam intro part doesn’t have a camera subject. By the way, the camera will go the the position of the place where the character spawned.

Well in that case I would have to inform you that my service would not be helpful. I do not have enough experience with the Camera to further help you, and would only be a confusing burden if I tried. I have only just recently this past week been messing with the Camera using scripts. I wish I could help further, but I honestly cannot. I hope someone else with more experience with the Camera can assist you, and solve your issue. I wish you the least stressful solution!

Thank you, for trying to help me at least! :+1: :+1: :+1:

1 Like