I’m currently working on a first-person shooter type of game and I’m having a small issue. The script goes into first-person when the player equips a tool and allows them to exit from first-person when they unequip the weapon. How do I make it so that the camera zoom is automatically set to 25 when they unequip the weapon also? I’m sorry if this is a silly question but I just finished writing this script and I don’t see the option anywhere in the StarterPlayer to set the player’s zoom. Thank you for taking time out of your day to read this!
I’m not a pro, but could it be the “CameraMaxZoomDistance” and “CameraMinZoomDistance”, found under “Camera”? I believe those set how far a player can zoom in or out, and if you set them to the same number, and a larger one, then the player would not be able to zoom in or out while using the tool and would be zoomed in closer, and then back to the default settings when the player is not holding the tool.
I don’t know if this would work, so Im’a go test it in studio real quick, brb
Edit: yep, we’re aight
If you set both the camera max zoom distance and the camera min zoom distance to this same number it will zoom the camera out to the said number. Then you can set the values to normal again and the camera will have zoomed out to your desired position. Hope this is what you were looking for
Thank you for your solution. But I don’t understand how to change the player’s camera position from a script. I only know how to set their CameraMode to LockFirstPerson or Classic. How would I set their Max and Min CameraZoom to 25? I tried Player.CameraMode.CameraMaxZoomDistance = 25
and Player.CameraMode.CameraMinZoomDistance = 25
but that didn’t seem to work. I’ve never scripted cameras before. Sorry for the inconvenience.
local Player = game.Players.LocalPlayer
local Character = Player.Character or Player.CharacterAdded:Wait()
Character.ChildAdded:Connect(function(NewChild)
if NewChild:IsA("Tool") then
Player.CameraMode = Enum.CameraMode.LockFirstPerson
end
end)
Character.ChildRemoved:Connect(function(RemovedChild)
if RemovedChild:IsA("Tool") then
Player.CameraMode = Enum.CameraMode.Classic
end
end)
I am very new to camera mechanics too, but I believe that CameraMaxZoomDistance and Camera MinZoomDistance are both properties of the player. So to change one you would just say:
player.CameraMaxZoomDistance = 25
By player I mean the player not the players character.
To, answer your question and elaborate on others, there is no property to set the players zoom nor is there a way to get it (using a property, you can of course use magnitude to somewhat get the zoom distance), in your case they easiest thing and will in fact work is to set the CameraMaxZoomDistance and CameraMinZoomDistance to the same number or set the min more than the max.
Example:
local player = game.players.LocalPlayer
player.CameraMaxZoomDistance = 50
player.CameraMinZoomDistance = 50
@K_daDJ, You are correct! you can utilize the CameraZoomDistance properties to set the player zoom, but you can set the player min/max zoom distance from both a local script and a normal script, but with a normal script you would have to find a way to reference/define the player. ( in most cases using it from a local script makes the most sense either way)
try this in local script:
localplr.CameraMode = "LockFirstPerson"
localplr.CameraMode = "Classic"
it sets the player zoom into first person and then allow players to zoom out