Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
✓ ANSWER ACCEPTED

How come my lock first person won't work?

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

lockCamera()

2 answers

✓ Accepted answer

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.

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"

2 comments

0

Awww dang you beat me...

0

Yours is nicer though ;p

This discussion is preserved as it was. New answers, comments, and votes are closed.