Hello guys! I’m trying to set the camera to a part, but I’m having trouble!
local camera = game.Workspace.Camera
local cameraTesting = workspace.CameraTest1
local cameraTesting2 = workspace.CameraTest2
function setCameraBeforeAnimation(part)
camera.CameraType = Enum.CameraType.Scriptable
camera.CFrame = part.CFrame
print("success")
end
setCameraBeforeAnimation(cameraTesting)
You need to add a small wait so that the camera can actually load before setting the camera’s properties.
This should work:
local camera = workspace.CurrentCamera
local cameraTesting = workspace.CameraTest1
local cameraTesting2 = workspace.CameraTest2
task.wait(2)
local function setCameraBeforeAnimation(part)
camera.CameraType = Enum.CameraType.Scriptable
camera.CFrame = part.CFrame
print("success")
end
setCameraBeforeAnimation(cameraTesting)
repeat
setCameraBeforeAnimation(cameraTesting) -- Calling your function
until camera.CameraType == Enum.CameraType.Scriptable -- Calling it until cam is scriptable
I managed to do it by connecting it to a render stepped function, as so. Thanks as always guys for the help!
local RS = game:GetService("RunService")
local camera = workspace.CurrentCamera
local cameraPart = game.Workspace.CameraTest1
local function updateCameraCFRAME()
camera.CameraType = Enum.CameraType.Scriptable
camera.CFrame = cameraPart.CFrame
camera.CameraSubject = cameraPart
end
local RsConnection = RS.RenderStepped:Connect(updateCameraCFRAME)
RsConnection:Disconnect()-- call this to disconnect function when needed then change camera back