Unable to assign property CFrame. CoordinateFrame expected, got nil

local uis = game:GetService("UserInputService")

local zoom = 100
local fieldOfView = 9

local player = game:GetService("Players").LocalPlayer

local character = player.Character or player.CharacterAdded:Wait()
local camera = workspace.CurrentCamera

local originalCameraCFrame = nil -- initialize it as nil

local function isometricCamera()
	game:GetService("RunService").RenderStepped:Connect(function()
		originalCameraCFrame = camera.CFrame -- set the variable to currennt camera's cframe
		camera.FieldOfView = fieldOfView
		camera.CameraType = Enum.CameraType.Custom

		if character then
			if character:FindFirstChild("Head") then
				game:GetService("SoundService"):SetListener(Enum.ListenerType.ObjectCFrame, character.Head)
				camera.CFrame = CFrame.new(Vector3.new(character.Head.Position.X + zoom, character.Head.Position.Y + zoom, character.Head.Position.Z + zoom), character.Head.Position)
			end
		end
	end)

end

local function basicCamera()
	--if camera.CFrame ~= nil then
		camera.CFrame = nil -- set the camera cframe
		camera.CameraType = Enum.CameraType.Custom
	--end
end

uis.InputBegan:Connect(function(input, chatting) 
	if chatting then return end -- if player is typing in chat this function will not run

	if input.KeyCode == Enum.KeyCode.F then
		isometricCamera()
	elseif input.KeyCode == Enum.KeyCode.R then
		basicCamera()
	end
end)

I’m trying to make it so that when you press F, there is one camera, and when you press R, a friend, but for some reason I have an error, what am I doing wrong?

camera.CFrame = nil
you’re not supposed to do this

i’m pretty sure you can remove that first part of basicCamera and only do camera.CameraType = Enum.CameraType.Custom

1 Like

Okay, but still, how do I fix the bug?

remove the camera.CFrame = nil
that’s it

I deleted it, but it didn’t fix the problem, now when you press R, nothing happens.

local function basicCamera()
	--if camera.CFrame ~= nil then
		--print(originalCameraCFrame, nil)
		--camera.CFrame = originalCameraCFrame -- set the camera cframe
		camera.CameraType = Enum.CameraType.Custom
	--end
end

uis.InputBegan:Connect(function(input, chatting) 
	if chatting then return end -- if player is typing in chat this function will not run

	if input.KeyCode == Enum.KeyCode.F then
		isometricCamera()
	elseif input.KeyCode == Enum.KeyCode.R then
		basicCamera()
	end
end)

i think i have an idea
you need to disconnect the renderstepped event that you make when you run isometricCamera

local uis = game:GetService("UserInputService")

local zoom = 100
local fieldOfView = 9

local player = game:GetService("Players").LocalPlayer
local runServ = game:GetService("RunService")
local camera = workspace.CurrentCamera

local isoCameraConnection

local function isometricCamera()
	if isoCameraConnection then isoCameraConnection:Disconnect() end
	isoCameraConnection = runServ.RenderStepped:Connect(function()
		camera.CameraType = Enum.CameraType.Scriptable
		camera.FieldOfView = fieldOfView

		if player.Character and player.Character:FindFirstChild("Head") then
			game:GetService("SoundService"):SetListener(Enum.ListenerType.ObjectCFrame, character.Head)
			camera.CFrame = CFrame.new(Vector3.new(character.Head.Position.X + zoom, character.Head.Position.Y + zoom, character.Head.Position.Z + zoom), character.Head.Position)
		end
	end)
end

local function basicCamera()
	if isoCameraConnection then
		isoCameraConnection:Disconnect()
		isoCameraConnection = nil
	end
	camera.CameraType = Enum.CameraType.Custom
end

uis.InputBegan:Connect(function(input, chatting) 
	if chatting then return end -- if player is typing in chat this function will not run

	if input.KeyCode == Enum.KeyCode.F then
		isometricCamera()
	elseif input.KeyCode == Enum.KeyCode.R then
		basicCamera()
	end
end)

You can not set a CFrame to nil. If you are trying to set the Camera back to focus on the player, simply change the camera.CameraSubject to the character’s Humanoid.