Need help with camera manipulation

what i’m trying to achieve is for the camera to be fixed on an invisible part, and when the player presses play, the camera is not stuck on that part anymore, but the players camera goes back to normal.

the camera becomes fixed to the part, but when i press play, nothing happens.
my script:

wait()
print("script is working.")

local btn = game.StarterGui.ScreenGui.TextButton
local cam = game.Workspace.CurrentCamera
local FocusPart = game.Workspace.FocusPart

cam.CameraType = "Scriptable"
cam.Focus = FocusPart.CFrame

wait(1)

btn.MouseButton1Click:Connect(function()
	local player = game.Players.LocalPlayer
	local human = player:FindFirstChild("Humanoid")
	if human then
		cam.CameraSubject = human
	end
end)

any help is appreciated!

2 Likes

Try setting the subject as the players character and not the humanoid.

1 Like

You also forgot to add .Character

Change to player.Character:FindFirstChild”Humanoid”)

2 Likes

At the 8th line of code. This is deprecated and its not efficient. I suggest changing it to this:

cam.CameraType = Enum.CameraType.Scriptable

hmm, the script doesn’t work…

Nevermind I spotted the mistake. The mistake is that you are using the ScreenGui and not the Player’s Gui.

wait()
print("script is working.")
local player = game.Players.LocalPlayer
local btn = player.PlayerGui.ScreenGui.TextButton
local cam = game.Workspace.CurrentCamera
local FocusPart = game.Workspace.FocusPart

cam.CameraType = Enum.CameraType.Scriptable
cam.Focus = FocusPart.CFrame

wait(1)

btn.MouseButton1Click:Connect(function()
	local human = player:FindFirstChild("Humanoid")
	if human then
		cam.CameraSubject = human
	end
end)
1 Like

damn it, it doesnt work again…

My bad on that one. As what @IEnforce_Lawz said

The code would look more like this:

wait()
print("script is working.")
local player = game.Players.LocalPlayer
local Character = player.Character or player.Character:Wait() --- Get the player's character
local btn = player.PlayerGui.ScreenGui.TextButton
local cam = game.Workspace.CurrentCamera
local FocusPart = game.Workspace.FocusPart

cam.CameraType = Enum.CameraType.Scriptable
cam.Focus = FocusPart.CFrame

wait(1)

btn.MouseButton1Click:Connect(function()
	if Character then
		cam.CameraSubject = Character

	end
end)
1 Like

Correction: CharacterAdded:Wait()

2 Likes

still doesn’t work. strange…

hm, that doesn’t work either.

my post didnt have enough letters

Try changing the CameraType back to Custom after you set the subject back as the player.

1 Like

AHHH. thank you. it works fine now.

1 Like