Something is wrong with CameraMaxZoomDistance property

I’m trying to set player’s CameraMaxZoomDistance to 0.5 when joins game but it doesn’t change:

local player = game:GetService("Players").PlayerAdded:Wait()

player.CameraMaxZoomDistance = 0.5

And I already fixed that problem by adding task.wait(0.1):

local player = game:GetService("Players").PlayerAdded:Wait()
player.CameraMaxZoomDistance = 0.5

But why it didn’t changed in the first script? If I don’t want to use task.wait(0.1) what should I do?

First, the property .CameraMaxZoomDistance belongs to a camera object.

Second, when you are trying to manipulate a player’s camera you should do it in a local script. You can read more at Customizing the Camera | Roblox Creator Documentation.

Put this line in a local script in the PlayerStarterScript folder

workspace:WaitForChild("Camera").CameraMaxZoomDistance = 0.5

Upon joining the game, the server will automatically set the MaxZoomDistance to the default. This overrides what your script set it to.

First, you’re wrong about this. Camera has no property “CameraMaxZoomDistance”. (You can also get the camera with workspace.CurrentCamera for ease of getting it.)

It’s a Player property, or StarterPlayer.

The script OP has changing the CameraMaxZoomDistance is exactly what you would do to override it with a script. However, the script is probably being fired after the PlayerAdded event is fired so there is no player.

@SuchTheLegendary You can do this to your code to get it working.

local players = game:GetService("Players")

function playerAdded(player: Player)
  player.CharacterAdded:Connect(function() --Wait for character so it's basically guaranteed they have their camera.
    player.CameraMaxZoomDistance = 0.5

for _, player in ipairs(players:GetPlayers()) do
  playerAdded(player) --Call our function on all players that joined in before the script connected to the PlayerAdded event

Or you can can just set the StarterPlayer property “CameraMaxZoomDistance” to 0.5.

Oh right i forgot. Next time I will check source before leaving a reply. Sorry

1 Like