Broken 2DCamera

I am looking for a solution to this problem but I cannot find it, my context is simple…

I have 3 proximities when activating one the camera changes to 2D, when activating the other it is the same in 2d but the position changes the same as the other

the problem occurs when the character dies in the local script. I’m still a chicken programmer, does anyone know how I can fix this? I am using a remote event for this situation, but I don’t think it is the problem, here is the place

2DCamera.rbxl (47,1 KB)

image

LocalScript

local RS1 = game:GetService("RunService")
local Plr1 = game:GetService('Players').LocalPlayer
local Char = Plr1.Character or Plr1.CharacterAdded:Wait()
local Camera = workspace.CurrentCamera

ChangeCamera.OnClientEvent:Connect(function(x,y,z)
	RS1:UnbindFromRenderStep(Plr1.UserId)
	local rootPart:BasePart = Char:WaitForChild('HumanoidRootPart')
	local function UpdateCamera()
		local Goal = CFrame.lookAt(
			rootPart.Position + Vector3.new(x, y, z),rootPart.Position
		)
		Camera.CFrame = Camera.CFrame:Lerp(Goal,.3)
		Camera.CameraType = Enum.CameraType.Scriptable
	end
	RS1:BindToRenderStep(Plr1.UserId,1,UpdateCamera)
end) 

Script

local ChangeCamera = game.ReplicatedStorage:WaitForChild("ChangeCamera")

game.Workspace.Primer1.ProximityPrompt.Triggered:Connect(function(plr)
	ChangeCamera:FireClient(plr,0,5,25)
end)

game.Workspace.Primer2.ProximityPrompt.Triggered:Connect(function(plr)
	ChangeCamera:FireClient(plr,0,5,-25)
end)

game.Workspace.Primer3.ProximityPrompt.Triggered:Connect(function(plr)
	ChangeCamera:FireClient(plr,0,10,0)
end)

The camera is not being reset when the character is respawned. You should add something bound to CharacterAdded to reset the camera to normal.

I made it but I don’t know how to place it well inside the code and it gave me errors :frowning:

Move this line into the function.

local function UpdateCamera()
    local rootPart:BasePart = Char:FindFirstChild('HumanoidRootPart')

    if rootPart == nil then return end

	local Goal = CFrame.lookAt(
		rootPart.Position + Vector3.new(x, y, z),rootPart.Position
	)
	Camera.CFrame = Camera.CFrame:Lerp(Goal,.3)
	Camera.CameraType = Enum.CameraType.Scriptable
end