When a player touches a Part I want the camera to change to a specific location and point in a particualr direction.
I have a local script which is a child of a cylinder part. There are no errors and print statements appear to have moved the camera but nothing changes and the camera remains unmoved.
I am very new to Roblox programming below is my local script code for changing the camera: (just a note that I have two block parts in the workspace called 'CameraPosition' and 'CameraLookAt' and I use these purely as a means to specify the position and orientation of the camera in the studio interface)
function updateCamera()
local targetPositionPart = workspace:WaitForChild("CameraPosition")
local lookAtPart = workspace:WaitForChild("CameraLookAt")
local currentCamera = workspace.CurrentCamera
while currentCamera.CameraType ~= Enum.CameraType.Scriptable do
print('currentCamera CameraType 1: '..tostring(currentCamera.CameraType)) -- break point here.
currentCamera.CameraType = Enum.CameraType.Scriptable
end
print('currentCamera CFrame 2: '..tostring(currentCamera.CFrame.Position))
currentCamera.CFrame = CFrame.new(targetPositionPart.CFrame.Position, lookAtPart.CFrame.Position)
print('currentCamera CameraType 3: '..tostring(currentCamera.CameraType))
print('currentCamera CFrame 4: '..tostring(currentCamera.CFrame.Position))
end
...and here is the print output:
currentCamera CameraType 1: Enum.CameraType.Fixed
currentCamera CFrame 2: 92.1606369, 10.7583599, -111.576591
currentCamera CameraType 3: Enum.CameraType.Scriptable
currentCamera CFrame 4: 60.3000221, 19.1000347, -109.999947
If I put a break-point on the print statement (line 07) in the while loop it does work, but it doesn't work during normal execution, so I think this may be something to do with me doing this in the wrong place? maybe you just can't do this in a local script maybe, I don't know, any pointers at all really greatly received, thank you very much for reading.
