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

How come my lock first person won't work?

Asked by 8 years ago
function lockCamera()
    for i, object in pairs(game.Players:GetChildren()) do
            object.CameraMode = Enum.CameraMode.LockFirstPerson
        end
    end

lockCamera()

2 answers

Log in to vote
0
Answered by
yelsew 205 Moderation Voter
8 years ago

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. LocalScripts 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.

Ad
Log in to vote
0
Answered by 8 years ago

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"

0
Awww dang you beat me... yelsew 205 — 8y
0
Yours is nicer though ;p darkelementallord 686 — 8y

Answer this question