How do I reset camera type and subject?

Hello everyone! I have, with help, managed to create this script.

local Camera = game.Workspace.CurrentCamera
game.ReplicatedStorage.RemoteEvent.OnClientEvent:Connect(function(Player)

print("1")

	Camera.CameraType = Enum.CameraType.Attach
	workspace.CurrentCamera.CameraSubject = workspace.Model.Part
	print("2")


wait(5)

local Players = game:GetService("Players")

local localPlayer = Players.LocalPlayer

local function resetCameraSubject()
	if workspace.CurrentCamera and localPlayer.Character then
		local humanoid = localPlayer.Character:FindFirstChildOfClass("Humanoid")
		if humanoid then 
			workspace.CurrentCamera.CameraSubject = humanoid
			end
		end	
	end
end)

What it does is focus the camera on a part.
What I want the bottom of the script to do, the part under wait(5), is reset the camera to the default camera. Following the player. How do I make it work? (It does not work at the moment)

2 Likes

To reset the camera, use this:

Camera.CameraType = Enum.CameraType.Custom

The camera should automatically jocus on the Player, and be normal.

Thank you for your reply. Unfortunately it doesn’t work. That might be because the camera is locked to a part. Any idea how to fix it?

You could potentially lock the camera subject to the player’s head. I believe that is how it is normally.

And how do I get the player? The script is run inside of starterplayerscripts, but to lock the camera to the head of the player I need to have the player’s name first… I think…

local localPlayer = Players.LocalPlayer

That variable in your script is the player. Just do localPlayer.Character.Head

1 Like

I just tried it. It did not work. Error: Players.UXZ16.PlayerScripts.LocalScript:12: attempt to index nil with ‘Character’ - Client - LocalScript:12

Could you send the updated script? Like dont change it, just leave line 12 so I can see what the problem is.

1 Like

Is it okay if I send it to you in ± 30-35 minutes? I’m going to eat right now.

That is alright. I will check back in a bit and see how I can help once you are back.

1 Like
local Camera = game.Workspace.CurrentCamera
game.ReplicatedStorage.RemoteEvent.OnClientEvent:Connect(function(Player)

print("1")

	Camera.CameraType = Enum.CameraType.Custom
	workspace.CurrentCamera.CameraSubject = workspace.Model.Part
	print("2")
	
	wait(6)
	
	workspace.CurrentCamera.CameraSubject = localPlayer.Character.Head
	
end)

You need to make a variable at the top of the script of the following:

local localPlayer = game.Players.LocalPlayer

You need to set the CameraSubject to the character’s humanoid not head.

1 Like

Oh… my bad for saying that. I guess Humanoid makes more sense.

1 Like

I’ve got another question if you don’t mind:

wait(1)
local Camera = game.Workspace.CurrentCamera
local localPlayer = game.Players.LocalPlayer
local ExitButton = game.Players.LocalPlayer.PlayerGui.ScreenGui.TextButton
game.ReplicatedStorage.RemoteEvent.OnClientEvent:Connect(function(Player)

print("1")

	Camera.CameraType = Enum.CameraType.Custom
	workspace.CurrentCamera.CameraSubject = workspace.Model.Part
	
	print("2")
	
	ExitButton.Visible = true
	
	
	if game.ReplicatedStorage.RemoteEvent2.OnClientEvent:Connect(function(Player)
		
	end)
		
		then
			workspace.CurrentCamera.CameraSubject = localPlayer.Character.Humanoid
	
			ExitButton.Visible = false
		
	end
end)

I’m doing something wrong here… The script just skips the remoteevent 2 thingy. It does not wait for it like I want it to.

Using an if statement to check if an event has ran won’t work.

What exactly are you trying to accomplish with that script? Reading it I don’t really understand the point of some of it.

My goal is to be able to click a part. (Works), which makes the camera focus on it (Works). Then for a button to pop up which you can click (works) and when you click on it to exit the focus mode on the part (doesn’t work yet).
The clicking of the button triggers remoteevent2.

The exit system works, but I need to connect that to remoteevent2 so it only happens when I click the button.

game.ReplicatedStorage.RemoteEvent2.OnClientEvent:Wait()

This won’t fix your script since there are other issues but this is how you would correctly wait for an event to fire before continuing on with the execution of the script.