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