Hey, I am a rookie scripter and I am trying to make a main menu where if you still didn’t close the menu and your perspective was still in the main menu camera, then when the intermission ended, teams were chosen, and game began, the game would close the main menu camera for you.
but instead, the entire perspective breaks, like, the camera is in some random spot, whilst the player is somewhere else.
Help would be really appreciated.
Here’s the script:
local Player = game.Players.LocalPlayer
local function myTeamChanged()
local MyTeam = Player.Team
if not MyTeam then
return -- Player is not in a team
end
local isInFirstPersonTeam = false
for _, teamName in ipairs({"TeamA", "TeamB"}) do
if MyTeam.Name == teamName then
isInFirstPersonTeam = true
break
end
end
-- Access the CameraScript from the Menu ScreenGui in StarterGui
local Menu = game.StarterGui.Menu
if Menu then
local CameraScript = Menu.CameraScript
if isInFirstPersonTeam then
Player.CameraMode = Enum.CameraMode.LockFirstPerson
if CameraScript then
CameraScript.Enabled = true -- Enable the CameraScript
end
else
Player.CameraMode = Enum.CameraMode.Classic
if CameraScript then
CameraScript.Enabled = false -- Disable the CameraScript
end
end
end
end
-- Initial check
myTeamChanged()
-- Listen for team changes
Player:GetPropertyChangedSignal("Team"):Connect(myTeamChanged)
I may be wrong, but I think that’s because you didn’t set the camera back to the player’s body. Try this instead:
if isInFirstPersonTeam then
Player.CameraMode = Enum.CameraMode.LockFirstPerson
Player.Camera.CameraType = Enum.CameraType.Custom -- This is Roblox's default camera type
if CameraScript then
CameraScript.Enabled = true -- Enable the CameraScript
end
else
Player.CameraMode = Enum.CameraMode.Classic
Player.Camera.CameraType = Enum.CameraType.Custom -- This is Roblox's default camera type
if CameraScript then
CameraScript.Enabled = false -- Disable the CameraScript
end
end
local Player = game.Players.LocalPlayer
local Camera = game.Workspace.CurrentCamera
local function myTeamChanged()
local MyTeam = Player.Team
if not MyTeam then return end
local isInFirstPersonTeam = false
for _, teamName in ipairs({"TeamA", "TeamB"}) do
if MyTeam.Name == teamName then
isInFirstPersonTeam = true
break
end
end
local Menu = game.StarterGui.Menu
if Menu then
local CameraScript = Menu.CameraScript
if isInFirstPersonTeam then
Player.CameraMode = Enum.CameraMode.LockFirstPerson
if CameraScript then CameraScript.Enabled = true end
else
Player.CameraMode = Enum.CameraMode.Classic
if CameraScript then
CameraScript.Enabled = false
Camera.CameraSubject = Player.Character
Camera.CameraType = Enum.CameraType.Custom
end
end
end
end
Player:GetPropertyChangedSignal("Team"):Connect(myTeamChanged)
myTeamChanged()