Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
COMMUNITY QUESTION

Camera Script printing 1000's of errors when Player Dies? [Solved]

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

1 answer

This discussion is preserved as it was. New answers, comments, and votes are closed.