Change Player Camera Mode on Reset

Hey there!
In my game, the default camera mode is third person, but once the player chooses a character to start off as, it switches them into first-person lock mode. The issue I’m having is that when they die, I can’t get the camera to go back to third person. I’ve tried many things, but none worked. When players reset, they can’t move their mouse to choose a new character to start as on the Gui. How do I change this?

1 Like

Can you provide the script? Without it, no one knows what is wrong.

It’s two scripts. Here’s the local script that changes it (Parent is Replicated First):

local SetSubject = game.ReplicatedStorage:WaitForChild("SetSubject")
local player = game.Players.LocalPlayer

function onEvent_SetSubject(Humanoid)
	workspace.CurrentCamera.CameraSubject = Humanoid

	player.CameraMode = Enum.CameraMode.LockFirstPerson
end

SetSubject.OnClientEvent:Connect(onEvent_SetSubject)

And here’s the normal script (Parent is ScreenGui in starterGui):

local Player = script.Parent.Parent.Parent
local Content = script.Parent.MainFrame.ScrollingFrame.Content
local Characters = game.ReplicatedStorage.Characters
local SetSubject = Characters.Parent.SetSubject

for index,item in pairs(Characters:GetChildren()) do
	if item:FindFirstChild("Humanoid") then
		local ViewportFrame = Instance.new("ViewportFrame")
		ViewportFrame.Parent = Content
		ViewportFrame.BackgroundTransparency = 1

		local Button = Instance.new("TextButton")
		Button.Parent = ViewportFrame
		Button.Position = UDim2.new(0,0,1,0)
		Button.Size = UDim2.new(1,0,0,15)
		Button.BorderSizePixel = 0
		Button.BackgroundColor3 = Color3.fromRGB(255,255,255)
		Button.Text = "Spawn"
		Button.TextScaled = true

		local Preview = item:Clone()
		Preview.Parent = ViewportFrame

		local Camera = Instance.new("Camera")
		Camera.Parent = ViewportFrame
		Camera.CFrame = Preview.Head.CFrame + Preview.Head.CFrame.LookVector * 5
		Camera.CFrame = CFrame.new(Camera.CFrame.Position,Preview.Head.Position)

		ViewportFrame.CurrentCamera = Camera

		Button.MouseButton1Down:Connect(function()
			script.Parent.Enabled = false
			local ChosenCharacter = item:Clone()
			local CurrentCharacter = Player.Character
			local LocalScripts = {}

			for index2,item2 in pairs(game.StarterPlayer.StarterCharacterScripts:GetChildren()) do
				if item2:IsA('LocalScript') then
					table.insert(LocalScripts,item2:Clone())
				else
					item2:Clone().Parent = ChosenCharacter
				end
			end

			CurrentCharacter.Health:Clone().Parent = ChosenCharacter
			table.insert(LocalScripts,CurrentCharacter.Animate:Clone())		
			ChosenCharacter.Parent = workspace
			Player.Character = ChosenCharacter
			for index2,item2 in pairs(LocalScripts) do
				item2.Parent = ChosenCharacter
			end	
			SetSubject:FireClient(Player,ChosenCharacter.Humanoid)

			local Connection

			local function onDied()
				wait(game.Players.RespawnTime)
				Player:LoadCharacter()
				script.Parent.Enabled = true
				if Connection then
					Connection:Disconnect()
				end
			end

			Connection = ChosenCharacter.Humanoid.Died:Connect(onDied)

		end)

	end
end

I’ve thought of using UserInputService, but that would take a lot of rearranging, and this seemed like it would be an easier fix.

1 Like

You forgot setting the camera to third person mode.

I tried adding it there, but it never worked. Where would I add it in?

		local function onDied()
			wait(game.Players.RespawnTime)
			Player.CameraMode = Enum.CameraMode.Classic
			Player:LoadCharacter()
			script.Parent.Enabled = true
			if Connection then
				Connection:Disconnect()
			end
		end
1 Like

That still didn’t work. It’s stuck in third person the whole time, except for player joining.

So can players choose a new character after dying now?

They always were able to, it’s just they can’t click the character they want to spawn as since they can’t move the mouse, because it’s locked in first person. So, yes and no.

Solution: I added in invisible text button and set Modal to true.

1 Like