I am making a game and I have a specific map that would be better if it was locked to First Person Mode. Does anyone know a method to lock a specific team to First Person Mode?
I tried using this script and putting it into a team but I’m not much of a scripter so I don’t know how it works
I recommend doing this from the client in a LocalScript.
First off, let’s get the local player and their character (so we know their camera is ready to be changed):
local Player = game.Players.LocalPlayer
local Character = Player.Character or Player.CharacterAdded:wait()
local FirstPersonTeamName = "TeamA" -- change this to whatever team you want locked in first person. ALL other teams will have the default camera. It will update if you switch their team later.
Next, let’s set up a function that will fire when their team changes
function myTeamChanged()
local MyTeam = Player.Team -- see https://developer.roblox.com/en-us/api-reference/class/Team
-- Example of how you can detect the team by name:
if MyTeam.Name == FirstPersonTeamName then
Player.CameraMode = Enum.CameraMode.LockFirstPerson
else
Player.CameraMode = Enum.CameraMode.Classic
end
end
Finally, we hook this function up like so (and we fire it with whatever the default team they got was):
if Player.Team then
myTeamChanged()
end
if Player.Team then
myTeamChanged()
end
Player.Changed:connect(function(Property)
if Property == "Team" then
myTeamChanged()
end
end)
This will instantly change their camera as their team changes.
No, you don’t, it automatically changes it back. Here’s the full code, I just wanted to break it down step-by-step so you can learn how it works
local Player = game.Players.LocalPlayer
local Character = Player.Character or Player.CharacterAdded:wait()
local FirstPersonTeamName = "TeamA" -- change this to whatever team you want locked in first person. ALL other teams will have the default camera. It will update if you switch their team later.
function myTeamChanged()
local MyTeam = Player.Team -- see https://developer.roblox.com/en-us/api-reference/class/Team
-- Example of how you can detect the team by name:
if MyTeam.Name == FirstPersonTeamName then
Player.CameraMode = Enum.CameraMode.LockFirstPerson
else
Player.CameraMode = Enum.CameraMode.Classic
end
end
if Player.Team then
myTeamChanged()
end
Player.Changed:connect(function(Property)
if Property == "Team" then
myTeamChanged()
end
end)
Edit: Place this in StarterPlayer.PlayerScripts as a LocalScript, and it’ll automatically handle it for you.
Looks like that’s still the same code, perhaps you copied+pasted before I edited it, try re-pasting it and giving it one more go. I tested it myself just to be certain it works.
Sorry for the inconvenience but there is a gun system that I’m using and after equipping it, it puts you back into classic mode. Is there a script that constantly checks to see if the user is in First Person Mode and if not it locks them back in?
You could make it a loop that’s constantly running, but that would be a significantly more laggy approach than an event listener, and is generally not the way to handle such a thing efficiently. Although possible, I don’t recommend it.
The better way would be to search the code for .CameraMode = and comment out the line that changes it, it won’t mess with anything else in the gun’s code.
-- Example of how you can detect the team by name:
if MyTeam.Name == FirstPersonTeamName then
Player.CameraMode = Enum.CameraMode.LockFirstPerson
else
Player.CameraMode = Enum.CameraMode.Classic
end
These are the lines I use to change the CameraMode, theirs will look very similar (but it may not say Enum.CameraMode.Classic, it could say 0 or Classic instead so try searching for .CameraMode = instead.