Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
✓ ANSWER ACCEPTED

How to solve HumanoidRootPart is not a valid member of Model?

I made a script witch should make players camera work like 2d game it works fine but once i die i get this error saying HumanoidRootPart is not a valid member of Model

local player = game.Players.LocalPlayer

local camera = workspace.CurrentCamera



player.CharacterAdded:Wait()

player.Character: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)

1 comment

0

Could you try putting a :WaitForChild() on HumanoidRootPart?

2 answers

✓ Accepted answer

You could add a wait or delay like:

delay(function(1) --//1 is the wait time
	local player = game.Players.LocalPlayer
	
	local camera = workspace.CurrentCamera
	
	
	
	player.CharacterAdded:Wait()
	
	player.Character: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)
end)

Lemme know if it works

Just check if it exists before continuing. You don't want to use WaitForChild inside of a Stepped event. It's pointless. Change lines 21-25 to what I have below.

game:GetService('RunService').Stepped:Connect(function()	 
        if not player.Character or not player.Character:FindFirstChild("HumanoidRootPart") then return end
 	camera.CFrame = CFrame.new(player.Character.HumanoidRootPart.Position) * CFrame.new(0,0,30)	 
end)

This discussion is preserved as it was. New answers, comments, and votes are closed.