Top down camera killing the player if going too high

Like I mentioned, if the player does goes like 6-7 Studs higher than the baseplate they die and I get this error message:

RunService:fireRenderStepEarlyFunctions unexpected error while invoking callback: HumanoidRootPart is not a valid member of Model "Workspace.Complicated_Copper"
local RS = game:GetService("RunService")	

local cam = workspace.CurrentCamera
local plr = game.Players.LocalPlayer

local offset = Vector3.new(0,50,0)
local fov = 70

cam.CameraType = Enum.CameraType.Scriptable

local function onRenderStep()
	if plr.Character then
		local plrPos = plr.Character.HumanoidRootPart.Position
		local camPos = plrPos + offset

		cam.FieldOfView = fov
		cam.CoordinateFrame = CFrame.new(camPos, plrPos)
	end
end

RS:BindToRenderStep("Camera", Enum.RenderPriority.Camera.Value, onRenderStep)

The reason why your character died is because at this line below as a variable, the camPos moves the Humanoid’s position. Thus, breaking your character.

local plrPos = plr.Character.HumanoidRootPart.Position
local camPos = plrPos + offset

What I would recommend doing instead is getting the distance as a number instead of a vector3, then changing the CFrame of the Camera.

local function onRenderStep()
	if plr.Character then
		local plrPos = plr.Character.HumanoidRootPart
		
        local distance = 25		
		cam.CoordinateFrame = CFrame.new(Vector3.new(plrPos.Position.x - 0.001, plrPos.Position.y + distance, plrPos.Position.Z),plrPos.Position)
		cam.FieldOfView = fov
	end
end
3 Likes