CurrentCamera not Detecting Humanoid to Change its Subject:

Hello, there!

I made a LocalScript that customizes the CurrentCamera of the player once joining the experience. I begin with creating variables and how its events are going to be structured as having multiple players added:

local ContentProvider = game:GetService("ContentProvider")
local Game_Camera = game.Workspace.Camera
local Game_StarterPlayer = game.StarterPlayer
local Player = game.Players.LocalPlayer.Character
local Humanoid = Player:FindFirstChildOfClass("Humanoid")

local Status = {Game_Camera, Game_StarterPlayer}

ContentProvider:PreloadAsync(Status)
print("Game Camera = True")

Game_Camera.CameraSubject = game.Workspace.CameraPart
Game_Camera.CameraType = Enum.CameraType.Scriptable
Game_Camera.CFrame = game.Workspace.CameraPart.CFrame
Game_StarterPlayer.CameraMode = Enum.CameraMode.LockFirstPerson
Game_StarterPlayer.CameraMaxZoomDistance = 0
Game_StarterPlayer.CameraMinZoomDistance = 0
Game_StarterPlayer.CharacterWalkSpeed = 0
Game_StarterPlayer.CharacterJumpPower = 0
Game_StarterPlayer.CharacterJumpHeight = 0

task.wait(3.75)
task.wait(5)
task.wait(0.01)
task.wait(10)
task.wait(5)
task.wait(5)
-- Ignore this little part of the waiting and its seconds...

Game_Camera.CameraSubject = Humanoid
Game_Camera.CameraType = Enum.CameraType.Custom
Game_StarterPlayer.CameraMode = Enum.CameraMode.Classic
Game_StarterPlayer.CameraMaxZoomDistance = 128
Game_StarterPlayer.CameraMinZoomDistance = 0.5
Game_StarterPlayer.CharacterWalkSpeed = 16
Game_StarterPlayer.CharacterJumpPower = 50
Game_StarterPlayer.CharacterJumpHeight = 50

Once tested, one code at line 5 (Humanoid) printed at the Output an error stating that I am attempting to do an index nil as within FindFirstChildOfClass. Quite strange that I never had this before… I tried using FindFirstChild, yet still remains.

image

Is there a possibility to fix this? If anyone knows, that would be appreciatable a lot!

I see your error. You have to say, Player.Character:FindFirstChildOfClass(“Humanoid”)
not just player:ect…

there may be another error, let me know if this fixed it.

local scripts load before character has a chance to load in fully
change line 4 to
local Player = game.Players.LocalPlayer.Character or game.Players.LocalPlayer.CharacterAdded:Wait()

^ single line, idk why it looks split up

1 Like

Hey, I apologize for the delayed response… @DevLazl & @DevLazl, I edited the script following both of your notes that were taken into consideration, and here is the result:

In the Output, the error does not print any further, but while testing the experience and seeing the events on the screen, it appears that my CurrentCamera is stuck to the Part while it should have changed to the character’s Humanoid…