function lockCamera() for i, object in pairs(game.Players:GetChildren()) do object.CameraMode = Enum.CameraMode.LockFirstPerson end end lockCamera()
This function is not working because it is not accessing anything. When a player joins a game on ROBLOX, the server has already started for them, and any scripts that are supposed to run on the server start run. In this case, this script is not being told to wait or stop until any players have joined. Because of this, the script is accessing nothing, and nothing is happening. Not only that, it is much more efficient to do this within a LocalScript
. LocalScript
s go into a special folder for scripts used on the players known as StarterPlayerScripts
.
--Put this script inside of StarterPlayerScripts game:GetService("Players").LocalPlayer.CameraMode = Enum.CameraMode.LockFirstPerson
This script will force first person on any player that joins the game, and will run once again after the player dies. I also advise to look at a few more wiki articles to help yourself on the journey of scripting.
This script will run once when the server starts, before any players have even joined. A better option would be to go to the Players service, and set "CameraMode" to "LockFirstPerson"