Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
✓ ANSWER ACCEPTED

Camera Does Not Focus As Required?

local rooms = game.Workspace:WaitForChild("Rooms")
local camera = game.Workspace:WaitForChild("Rooms"):WaitForChild("Camera1")
local target = game.Workspace:WaitForChild("Rooms"):WaitForChild("Target1")
local cam = game.Workspace.CurrentCamera
local Button = script.Parent


function SendCamera()
repeat wait() until game.Workspace:WaitForChild("Rooms"):WaitForChild("Camera1")
cam.CameraSubject = camera
cam.CameraType="Attach"
cam.Focus=CFrame.new(target.Position,CFrame(-180,0,-180))
cam.CoordinateFrame= CFrame.new(target.Position,camera.Position)
wait(1)
game.Workspace.Camera.CameraType="Scriptable"
end

Button.MouseButton1Click:connect(SendCamera)

for some reason its also being delayed and requires 2 clicks instead of 1? but anyway what should happen is that there is a block called Target 1 which is infront of Camera1 another part. The camera needs to focus on target but all it ends up doing is facing upwards

1 answer

✓ Accepted answer

Just use "Scriptable". The other camera modes are rarely useful. Similarly, .Focus is rarely useful.

You want the camera to be looking from camera.Position towards target.Position.

The CFrame constructor CFrame.new(from, to) produces such a CFrame:

function SendCamera()
	cam.CameraType = "Scriptable"
	cam.CFrame = CFrame.new(camera.Position, target.Position)
end

Hygiene

Tab and space your code properly.

Use workspace instead of game.Workspace.

You shouldn't be using repeat wait() until workspace:WaitForChild("Rooms"):WaitForChild("Camera1"). Firstly, because you've already waited at the beginning of the script; secondly, because the repeat is pointless. The :Wait suggests it's already waiting -- no loop required.

This discussion is preserved as it was. New answers, comments, and votes are closed.