Camera.CFrame won't change position

I wanted to mess with the player’s camera to get the hang of how to use and script the camera. I have this inside of StarterPlayerScripts (localscript)

local cam = workspace.CurrentCamera
repeat
	cam.CameraType=Enum.CameraType.Scriptable
until
cam.CameraType==Enum.CameraType.Scriptable
while wait(0.5) do
cam.CFrame = workspace.EEme.CFrame
end

This makes the camera face where the part (“EEme”) is facing, yet it doesn’t teleport to it’s position.

Try waiting for the Part instead to first load?

local cam = workspace.CurrentCamera
local Part = workspace:WaitForChild("EEme")
print("This should work")

repeat 
    cam.CameraType=Enum.CameraType.Scriptable
until cam.CameraType==Enum.CameraType.Scriptable

while wait(0.5) do
    print("Should set the Camera's CFrame properly")
    cam.CFrame = Part.CFrame
end

Check your Output for any potential errors

local cam = workspace.CurrentCamera
local EEme = workspace:WaitForChild("EEme")

repeat
	task.wait()
	cam.CameraType = Enum.CameraType.Scriptable
until cam.CameraType == Enum.CameraType.Scriptable

while task.wait(0.5) do
	cam.CFrame = EEme.CFrame
end

Add a yield inside the repeat loop.

Instead of
cam.CFrame = workspace.EEme.CFrame
I replaced it with
cam.CFrame = workspace:WaitForChild("EEme").CFrame
This still does the same thing, I don’t believe it’s because the part hasn’t loaded due to the fact that the camera’s rotation is changed.

The while loop works fine, when I move my camera it teleports back every 0.5 esconds

local cam = workspace.CurrentCamera
local EEme = workspace:WaitForChild("EEme")

repeat
	task.wait()
	cam.CameraType = Enum.CameraType.Scriptable
until cam.CameraType == Enum.CameraType.Scriptable

cam.CameraSubject = EEme

Sounds like you want to make it the camera’s subject.

Is your wait(0.5) call meant to simulate the camera constantly moving during the game running? If so, use RenderStepped to update the position every frame.

To create a CFrame Positioned at Position1 and Looking at Position2:

cam.CFrame = CFrame.lookAt(cam.CFrame.Position, EEme.CFrame.Position)

Are you wanting to just set where the Camera is currently looking? Or are you just wanting a smooth transition for the Camera instead?

local cam = workspace.CurrentCamera
local EEme = workspace:WaitForChild("EEme")
local ts = game:GetService("TweenService")

repeat
	task.wait()
	cam.CameraType = Enum.CameraType.Scriptable
until cam.CameraType == Enum.CameraType.Scriptable

while task.wait() do
	ts:Create(cam, TweenInfo.new(0.1), {["CFrame"] = EEme.CFrame})
	ts:Play()
end

I am unsure why, but this makes the camera gaze into completely nothing. Here are the 4 possible lookVector viewpoints





There isn’t a single rotation where the camera won’t see another part. (If the position was set to the EEme)

Another test I did was putting “EEme” in a complete sealed box, still staring into the distance (nothing)

You don’t need to loop anything. Try this:

local Camera = workspace.CurrentCamera
local CameraDestination = game.Workspace:FindFirstChild("EEme")

Camera.CameraType=Enum.CameraType.Scriptable

task.wait(0.1)

Camera.CFrame = CameraDestination.CFrame

Since you stated the while loop, the system knows you want it to be at that CFrame every 0.5 seconds, which is why it teleports back every 0.5 seconds.

The issue you are running into is that the server is overriding your CameraType change. When the player is first spawned, the game likes to automatically set the CameraType back to custom.

Here’s my way of working with the camera. Usually I implement this inside a module called CameraService, but my example will be within your script you provided.

-- local script placed within StarterPlayerScripts

local cam = workspace.CurrentCamera

-- your specified camera type
local cameraType = Enum.CameraType.Scriptable

-- getting the signal that fires when the CameraType property changes
local camTypeChanged = cam:GetPropertyChangedSignal("CameraType")

-- setting initial camera type
cam.CameraType = cameraType

-- funtion that runs when camera type changes
camTypeChanged:Connect(function(newType)
	-- if camera type is not the specified value, then reset it back
	if newType ~= cameraType then
		cam.CameraType = cameraType
	end
end)

-- function you can use to change the camera's type
function setCameraType(newCameraType)
	cameraType = newCameraType
	cam.CameraType = newCameraType
end

-- the rest of your code unchanged
while wait(0.5) do
	cam.CFrame = workspace.EEme.CFrame
end

This ensures that the server will not override your camera type changes. However, if you ever want to change the CameraType, you need to call the function within this script (setCameraType)
That’s why I normally put my camera manipulating code within a module script so any script can access the code.

Hope this helps!

4 Likes

Correct me if I’m wrong, but ModuleScripts need to return a value; You might want to return the CameraType, instead of printing it. Also, if multiple people are using the script, it could spam the output.

1 Like

You’re right, the code I provided is not a module script, but rather just a local script. If it were a module script, it would be coded differently.

I didn’t realize I forgot to remove the print statement. I used that to see if the camera type was being overridden.

Correct. I’m going to remove the print statement from the code, thanks for pointing this out.

1 Like