Camera control issues

I want to change the current camera around in a script, but when i set the camera back to the original one, it snaps back to world origin after 1 frame.

game.Players.LocalPlayer.Character:WaitForChild("Humanoid")
print("a")
UserInputService = game:GetService("UserInputService")
MainCam = workspace.CurrentCamera
SpecPart = workspace.wee

local function UnSpec(Input,idk)workspace.CurrentCamera = MainCam
	workspace.CurrentCamera.CameraSubject = game.Players.LocalPlayer.Character.Humanoid
	workspace.CurrentCamera.CameraType = "Custom"
	task.wait(0)
end

MainCam = workspace.CurrentCamera
UserInputService.InputBegan:Connect(function(input)
	print(input)
	if input.UserInputType == Enum.UserInputType.MouseButton1 then
		workspace.CurrentCamera = SpecPart.Camera
	elseif input.UserInputType == Enum.UserInputType.MouseButton2 then
		UnSpec()
	end
end)

Instance.new("Camera").Parent = SpecPart
SpecPart.Camera.CameraType = "Custom"
SpecPart.Camera.CameraSubject = SpecPart

I have looked at camera documentaion and other stuff, and no one ive seen has encountered this issue with this kind of manipulation to the camera

This property can be set. When it is set, all other Camera objects in the Workspace are destroyed, including the previous CurrentCamera.

  • page for CurrentCamera here

if it’s of any consolation, ur method would have worked in like any other game engine

you can fix it pretty easily by thinking of the camera being a singular instance that you change whenever you need it to look somewhere else

1 Like

Is this what you were looking to achieve?
localscript in startercharacterscript:

local h:Humanoid = game.Players.LocalPlayer.Character:WaitForChild("Humanoid", 10)
if h == nil then
	warn("Error, cannot access humanoid.")
	return
end

UserInputService = game:GetService("UserInputService")

local p:Part = Instance.new("Part")
p.Color = Color3.new(1, 0, 0)
p.CFrame = CFrame.new(52,2,0)
p.Size = Vector3.new(4,4,4)
p.Name = "wee"
p.Parent = workspace

local h:HingeConstraint = Instance.new("HingeConstraint")
local a1:Attachment = Instance.new("Attachment")
a1.CFrame = CFrame.new() * CFrame.Angles(0,0,math.pi * .5)
a1.Name = "Rotate1"
a1.Parent = p
h.Attachment0 = a1
h.ActuatorType = Enum.ActuatorType.Motor
h.AngularVelocity = 4
h.MotorMaxTorque = 10000
local a2:Attachment = Instance.new("Attachment")
a2.Name = "Rotate2"
h.Attachment1 = a2
h.Parent = p
a2.Parent = workspace.Baseplate
a2.WorldCFrame = a1.WorldCFrame * CFrame.new(1,0,0)

local h2:HingeConstraint = Instance.new("HingeConstraint")
h2.Name = "OrbitHinge"
local a1a:Attachment = Instance.new("Attachment")
a1a.CFrame = CFrame.new(6,0,0) * CFrame.Angles(0,0,math.pi * .5)
a1a.Name = "Orbit1"
a1a.Parent = p
h2.Attachment0 = a1a
h2.ActuatorType = Enum.ActuatorType.Motor
h2.AngularVelocity = 3
h2.MotorMaxTorque = 10000
local a2a:Attachment = Instance.new("Attachment")
a2a.Name = "Orbit2"
h2.Attachment1 = a2a
h2.Enabled = false
h2.Parent = p
a2a.Parent = workspace.Baseplate
a2a.WorldCFrame = a1a.WorldCFrame * CFrame.new(1,0,0)

SpecPart = workspace.wee
local cf = workspace.CurrentCamera.CFrame
local cct = workspace.CurrentCamera.CameraType
local cs = workspace.CurrentCamera.CameraSubject
local focus = workspace.CurrentCamera.Focus


local function UnSpec(Input,idk)
	workspace.CurrentCamera.CameraSubject = cs
	workspace.CurrentCamera.Focus = focus
	workspace.CurrentCamera.CFrame = cf
	workspace.CurrentCamera.CameraType = cct
	
end


UserInputService.InputBegan:Connect(function(input:InputObject)
	if input.UserInputType == Enum.UserInputType.Keyboard and input.KeyCode == Enum.KeyCode.V then
		workspace.CurrentCamera.CFrame = SpecPart.CFrame * CFrame.new(0,3,8) * CFrame.Angles(-math.pi/7,0,0)
		workspace.CurrentCamera.Focus = SpecPart.CFrame
		workspace.CurrentCamera.CameraSubject = SpecPart
		
	elseif input.UserInputType == Enum.UserInputType.Keyboard and input.KeyCode == Enum.KeyCode.B then
		UnSpec()
		
	elseif input.UserInputType == Enum.UserInputType.Keyboard and input.KeyCode == Enum.KeyCode.N then
		h2.Enabled = not h2.Enabled
		h.Enabled = not h.Enabled
	end
end)

I reparented the camera to a configuration and it works

Roblox is an enigma that i will never truly understand
Thank you lol
It meant it when it said it would destroy cameras under workspace

1 Like

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.