CameraType property not changing

I have a problem and it is that the camera won’t set to the NPC. I’m trying to change the camera in front of the NPC while the dialog is running.

From what I’ve observed the CameraType property is not changing whenever I run the code :
Camera.CameraType = Enum.CameraType.Scriptable

It stays as Custom and never changes to Scriptable.

Here is my code hopefully someone helps with a solution. Everything works except that the Camera doesn’t do anything.

local Camera = workspace.CurrentCamera
local CameraPart = script.Parent.CameraPart

local function enterCamera(player) 
	repeat wait() until player.Character
	Camera.CameraType = Enum.CameraType.Scriptable
	Camera.CFrame = CameraPart.CFrame

local function exitCamera()
	if Camera.CameraType == Enum.CameraType.Scriptable then
		Camera.CFrame = Camera.CFrame

local firstmessage = {"Hello there!", "I have some props to offer for you!"}

	plr.PlayerGui.NPCDialogue.Enabled = true
	plr.PlayerGui.NPCDialogue.Frame.NPCName.Text = "---"

	for i, v in pairs(firstmessage) do
		for i = 1, string.len(v) do wait(0.025)
			plr.PlayerGui.NPCDialogue.Frame.Message.Text = string.sub(v, 1, i)
		wait(string.len(v) / 10)
	-- plr.PlayerGui.NPCDialogue.Frame.OpenButton.Visible = true
	-- plr.PlayerGui.NPCDialogue.Frame.ContinueButton.Visible = true
	-- plr.PlayerGui.NPCDialogue.Frame.ExitButton.Visible = true

Hello, I think I found your problem.

If you are running this in a script - CurrentCamera can’t be accessed as it is local.
I recreated your scenario however used a LocalScript in StarterCharacterScripts and it worked flawlessly.

Is there any way to do this without using LocalScript on SCS (Starter Character Scripts)

Yes of course.
You can fire a remote event with :FireClient() and pick this up using a LocalScript (in StarterGui or any other place).
Then when fired change the Camera CFrame.

Thank you, man! I followed your steps! It worked! Here is what I did:

I created a LocalScript on SCS (Starter Character Scripts) that checks if the RemoteEvent was fired.

local Camera = workspace.CurrentCamera

local re = game:GetService('ReplicatedStorage')

	Camera.CameraType = Enum.CameraType.Scriptable
	repeat wait()
		Camera.CameraType = Enum.CameraType.Scriptable
	until Camera.CameraType == Enum.CameraType.Scriptable
	Camera.CFrame = CameraPart.CFrame

And then created a Script inside the NPC with the following code:

local re = game:GetService('ReplicatedStorage')
local DialogueEvent = re.DialogueEvent


Thanks man for the solution!

1 Like

The server does have a camera but its viewport size is 1x1 pixels.