This is my camera script
I'm having a Problem with the Script because when the Player Dies it Prints an error 1000's of times and It causes lag on the Client.
Camera LocalScript in PlayerScripts
while wait(1) do
local offset = Vector3.new(0,0,90)
local player = script.Parent.Parent
local fieldOfView = 30
local camera = game.Workspace.CurrentCamera
local runService = game:GetService("RunService")
camera.FieldOfView = fieldOfView
local function onRenderStep()
local playerPosition = player.Character:FindFirstChild("Torso").Position
if playerPosition then
local cameraPosition = playerPosition + offset
camera.CoordinateFrame = CFrame.new(cameraPosition, playerPosition)
end
end
if player.Character:FindFirstChild("Torso").Position then
runService:BindToRenderStep('Camera', Enum.RenderPriority.Camera.Value, onRenderStep)
end
end
It is printing an error saying
attempt to index nil with 'Position'
Solution: I just added Pcall function into the camera script and no more errors and also the camera is now connected to HumanoidRootPart
