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

HumanoidRootPart is not a valid member of model?

When I try to get the HumanoidRootPart it keeps giving me an error saying that it isn't a member of the model. Can someone tell me what I'm doing wrong?

local cam = workspace.CurrentCamera
local offset = Vector3.new(10,50,10)
local player = game.Players.LocalPlayer
local runService = game:GetService('RunService')
local function cameraManipulation()
	local character = player.Character or player.CharacterAdded:Wait()
	local playerPosition = character.HumanoidRootPart.Position
	local cameraPosition = playerPosition + offset
	cam.CameraType = 'Scriptable'
	cam.CoordinateFrame = CFrame.new(cameraPosition, playerPosition) * CFrame.Angles(math.rad(10),math.rad(-10),math.rad(0))
end
runService:BindToRenderStep('Camera', Enum.RenderPriority.Camera.Value, cameraManipulation)

1 comment

0

Try using character:WaitForChild("HumanoidRootPart").Position

1 answer

✓ Accepted answer

You can try Making it wait until HumanoidRootPart Is Avaliable, here is the script:

local cam = workspace.CurrentCamera
local offset = Vector3.new(10,50,10)
local player = game.Players.LocalPlayer
local runService = game:GetService('RunService')
local function cameraManipulation()
    local character = player.Character or player.CharacterAdded:Wait()
    local HRP = character:WaitForChild("HumanoidRootPart")
    local playerPosition = HRP.Position
    local cameraPosition = playerPosition + offset
    cam.CameraType = 'Scriptable'
    cam.CoordinateFrame = CFrame.new(cameraPosition, playerPosition) * CFrame.Angles(math.rad(10),math.rad(-10),math.rad(0))
end
runService:BindToRenderStep('Camera', Enum.RenderPriority.Camera.Value, cameraManipulation)

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