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

Attempt to index nil with CameraMaxZoomDistance? Can someone help?

so I'm making this invisible block that when you touch it forces you into first-person perspective. I got an error saying "Workspace.FirstPersonActivator.Script:3: attempt to index nil with 'CameraMaxZoomDistance'" in the output box. I don't understand the error message. can someone help?

local player = game.Players.LocalPlayer

script.Parent.Touched:Connect(function()
	player.CameraMaxZoomDistance = 0.5 
end)

1 comment

0

Whenever your dealing with cameras make sure you use Enum

1 answer

Usually I do not use local scripts inside the workspace, so instead I would use something like this in a normal script:

script.Parent.Touched:Connect(function(hit)
	local hum = script.Parent:FindFirstChild("Humanoid")
	local player = game.Players:GetPlayerFromCharacter(hit.Parent)
	if player then
		player.CameraMode = Enum.CameraMode.LockFirstPerson
	end
end)

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