Issue with automatically setting the camera into 1st person mode only using script after waiting for a while

What I am trying to do with my script is when you wait for a while, the game sets the camera into first person by force. Here is my script.

game.StarterPlayer.CameraMaxZoomDistance = 20 ---The starting Distance
wait(10)
game.StarterPlayer.CameraMaxZoomDistance = 0.5 --- Sets into First person mode

I have putted this script on workspace so if there is something I did wrong, please contact me. Thank you!

2 Likes

In case you still dont know, you first freely go into third or first person, but after a while, you are forced to be in first person view.

1 Like

The fact is that you use StarterPlayer, and it changes the camera only after respawn, in order to change the camera at a particular moment, you need to use:

For Local Script

local Player = game.Players.LocalPlayer

Player.CameraMaxZoomDistance = 20

task.wait(10)

Player.CameraMaxZoomDistance = .5

For Server Script

  1. Create a RemoteEvent and put it in ReplicatedStorage and name it CameraEvent
  2. Create a server script in Workspace or ServerScriptService and put this in there
local CameraEvent = game.ReplicatedStorage:WaitForChild("CameraEvent")

CameraEvent:FireAllClients(20) -- Instead of 20, enter the number of maximum camera distance you need

task.wait(10)

CameraEvent:FireAllClients(0.5) -- Instead of 0.5, enter the number of maximum camera distance you need
  1. Create a local script and put it in StarterGui or StarterPlayerScripts and type this in there:
local CameraEvent = game.ReplicatedStorage:WaitForChild("CameraEvent")

local Player = game.Players.LocalPlayer

CameraEvent.OnClientEvent:Connect(function(Focus)
   Player.CameraMaxZoomDistance = Focus
end)

If you want smooth zoom then paste this in Local Script:

local TweenService = game:GetService("TweenService")

local CameraEvent = game.ReplicatedStorage:WaitForChild("CameraEvent")

local Player = game.Players.LocalPlayer

CameraEvent.OnClientEvent:Connect(function(Focus)
   TweenService:Create(Player, TweenInfo.new(.7, Enum.EasingStyle.Quad, Enum.EasingDirection.Out), {
      CameraMaxZoomDistance = Focus
   }):Play()
end)
1 Like

its not working, for the (Server script), do I rename my script into “Server Script” or move it to server script service?

2 Likes

Instead of CameraMaxZoomDistance, you can try and use game.Players.LocalPlayer.CameraMode = Enum.CameraMode.LockFirstPerson in a LocalScript. (I would put it in StarterCharacterScripts)

2 Likes

I have corrected my code, try now

2 Likes

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.