Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
0

The word Character is not working on my local script Is it a outdated word?

Asked by 4 years ago

Hello I was watching a tutorial on youtube here is the link. https://www.youtube.com/watch?v=KV5AM-yYAlk and he teaching and explaining I did exactally what he said and relized it didn't work...This video was made 1 year ago so I don't think it is outaded but here is the script he typed.

local Camera = game.Workspace.CurrentCamera
local player = game.Players.LocalPlayer

player.CharacterAdded:wait()
player.CharacterAdded:WaitForChild("HumanoidRootPart")

Camera.CameraSubject = player.Character.HumanoidRootPart
Camera.CameraType = Enum.CameraType.Attach
Camera.FieldOfView = 40

game:GetService("RunService").Stepped:Connect(function()
    Camera.CFrame = player.Character.HumanoidRootPart.Position * Camera.new(0, 0, 30)
end)

So basically this is a 2d camera setting script and I get these error

WaitForChild is not a valid member of RBXScriptSignal PlayerScripts.CameraScript:6: attempt to index nil with 'HumanoidRootPart'

So what I understand from here is that the word Character does not work because all of this line have the word Character in it. How do I fix it? Or How do I make it simular to this if the code is outdated?

2 answers

Log in to vote
2
Answered by 4 years ago

The problem is that you're saying:

player.CharacterAdded:WaitForChild("HumanoidRootPart")

"CharacterAdded" does not have any children. It's not an object, it's an event. So change line 5 to:

player.Character:WaitForChild("HumanoidRootPart")

Please accept if this helps!

Thanks!

Ad
Log in to vote
0
Answered by 4 years ago
Edited 4 years ago

Did you mean to put this on line 12?

Camera.CFrame = CFrame.new(player.Character.HumanoidRootPart.Position) * CFrame.new(0, 0, 30)

(Character is not outdated/depricated)

Or here is the whole thing

local Camera = game.Workspace.CurrentCamera
local player = game.Players.LocalPlayer

player.CharacterAdded:wait()
player.CharacterAdded:WaitForChild("HumanoidRootPart")

Camera.CameraSubject = player.Character.HumanoidRootPart
Camera.CameraType = Enum.CameraType.Attach
Camera.FieldOfView = 40

game:GetService("RunService").Stepped:Connect(function()
    Camera.CFrame = CFrame.new(player.Character.HumanoidRootPart.Position) * CFrame.new(0, 0, 30)
end)

Answer this question