Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
0

Attempt to index nil with CameraMaxZoomDistance? Can someone help?

Asked by 4 years ago

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)
0
Whenever your dealing with cameras make sure you use Enum JesseSong 3916 — 4y

1 answer

Log in to vote
0
Answered by 4 years ago

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)

Ad

Answer this question