Is there a way to lock only 1 team to First Person

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

local player = game.Players.LocalPlayer

player.CameraMode = Enum.CameraMode.LockFirstPerson

Sooo, just one team? Or everyone?

I want it to be Locked to First Person Mode for just one team.

Use what @Xeptix gave, mine may not of even worked cause I didn’t have studio open and can’t think of the best way at the moment

1 Like

That’s very possible.

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.

1 Like

Do I make the script that changes the camera back when the person is not on the team anymore separate?

Also, could you combine it all into one script for me, I think I’m doing it wrong because It’s not working.

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 :slight_smile:

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.

It doesn’t work, am I doing anything wrong?

Screenshot_678

Ah, my bad, made a mistake (running off barely any sleep lol).

I’ll edit my posts to reflect the fixes.

edit: alright, try now.

1 Like

I suggest using player.MaxZoomDistance = 0.5

It still doesn’t work, sorry if I’m bothering you lol

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.

Make sure it’s a LocalScript running from where a local script can run.

2 Likes

Yes, also this ^

The latest version in my post works for me: https://gyazo.com/f95a50bb0349910c94a06306539315c9

Where can local scripts run? Not much of a scripter as stated before, lol

NVM Got it, thanks for all the help.

1 Like

It needs to be in a “LocalScript.”

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.