Cframe camera script fix

I’m trying to make the main menu where the player’s camera is staring at a block look like this:


but whenever I join the game the camera isn’t working how I want it too.

This is how my script looks.

Also please note that I’m very new to scripting.

Well, you’re on the right path. The only issue is that you didn’t set the CFrame of the camera. Add that in and you’ll be good to go. Keep Focus in since it has relevance to rendering.

Just above where you set Focus, add this:

camera.CFrame = target.CFrame

See the Camera documentation page for more information.

1 Like

Thank you for responding but it still doesn’t appear to work.


This is what it looks like now, also there appears to be a problem with end I think:
Screenshot_95

That’s a different error from your end unrelated to the Camera CFrame. Remove the first end and remove the brackets from the leftover one.

local function updateCamera()

end
1 Like

Ok, I thank you again for helping but it still doesn’t work for some reason.

I checked the output just in case:
Screenshot_97
Screenshot_98
this is all I found there.
Next, I changed the brick name to this:
Screenshot_99
Screenshot_100
But it still doesn’t work so I’m wondering what I’m doing wrong.

local TweenService = game:GetService("TweenService")
local RunService = game:GetService("RunService")

local Target = workspace:FindFirstChild("test object") or workspace:WaitForChild("test object")
local Camera = workspace.Camera
Camera.CameraType = Enum.CameraType.Scriptable
Camera.CFrame = CFrame.new(Target.CFrame.p + Target.CFrame.lookVector * 25, Target.CFrame.p)
--I'd recommend changing 25 as it is the distance from the part.

wrote this little bit up and tested it out in a place of my own, and as long as you have it in a local script it should work fine.

1 Like

Might as well point out: this is redundant. WaitForChild performs a FindFirstChild call internally and if that call fails, then it yields the thread until a child exists that matches the passed name. You only need to use WaitForChild here.

1 Like

You see, something like that would seem self explanatory as it states “as soon as it is ready”, but I just never thought about it.