HumanoidRootPart is not a valid member of Model Error

Hi, I am trying to make a map that uses a camera and follows your character. https://www.youtube.com/watch?v=GPV5DqFPW_k&t=113s As seen in this video.

However I keep getting the error ‘HumanoidRootPart is not a valid member of Model’ in the output window.

Here is the code:

local CircularMap = game.ReplicatedStorage.CircularMap:Clone()
CircularMap.Parent = workspace

local FakeCam = Instance.new("Camera")
FakeCam.Parent = script.Parent
FakeCam.CameraType = Enum.CameraType.Scriptable

script.Parent.Adornee = CircularMap.PrimaryPart
script.Parent.ViewportFrame.CurrentCamera = FakeCam	

workspace.Map:Clone().Parent = script.Parent.ViewportFrame

while true do
	CircularMap:SetPrimaryPartCFrame(workspace.CurrentCamera.CFrame*CFrame.Angles(math.rad(90),0,0)*CFrame.new(0,-10,0))
	FakeCam.CFrame = CFrame.new(game.Players.LocalPlayer.Character.HumanoidRootPart.Position + Vector3(0,10,0),game.Players.LocalPlayer.Character.HumanoidRootPart.Position)
	game:GetService("RunService").RenderStepped:Wait()
end

All help is greatly appreciated!

6 Likes

you have a few options, you could do

local player = game.Players.LocalPlayer
local character = player.Character

while true do
	if character:FindFirstChild("HumanoidRootPart") then
		--code here
	end
end

or you could change everywhere it says

game.Players.LocalPlayer.Character.HumanoidRootPart

to something like

game.Players.LocalPlayer.Character:WaitForChild("HumanoidRootPart")

I recommend the first one

One more thing that is very important about loops, when you have

while true do
end

it will try and run that loop as fast it can. add a wait() in the loop

edit: i just noticed you have

game:GetService("RunService").RenderStepped:Wait()

you should probably just use wait() instead

3 Likes

I just tried your second option and now there is an error that says [Players.Programmed_Model.PlayerGui.SurfaceGui.LocalScript:15: attempt to call global ‘Vector3’ (a table value)

CODE:

local CircularMap = game.ReplicatedStorage.CircularMap:Clone()
CircularMap.Parent = workspace

local FakeCam = Instance.new("Camera")
FakeCam.Parent = script.Parent
FakeCam.CameraType = Enum.CameraType.Scriptable

script.Parent.Adornee = CircularMap.PrimaryPart
script.Parent.ViewportFrame.CurrentCamera = FakeCam	

workspace.Map:Clone().Parent = script.Parent.ViewportFrame

while true do
	CircularMap:SetPrimaryPartCFrame(workspace.CurrentCamera.CFrame*CFrame.Angles(math.rad(90),0,0)*CFrame.new(-10,-10,-5))
	FakeCam.CFrame = CFrame.new(game.Players.LocalPlayer.Character:WaitForChild("HumanoidRootPart").Position + Vector3(0,50,0),game.Players.LocalPlayer.Character:WaitForChild("HumanoidRootPart").Position)
	game:GetService("RunService").RenderStepped:Wait()
	wait()
end
1 Like

change Vector3() to Vector3.new()

2 Likes

Use the following strings to define parts of the character:

local player = game:GetService('Players').LocalPlayer
local character = player.Character or player.CharacterAdded:wait()
local HumanoidRootPart = character:WaitForChild('HumanoidRootPart')

Additionally, optimize your while loop by binding the enclosed function inside of a RenderStepped loop:

local RunService = game:GetService('RunService')
RunService.RenderStepped:Connect(function()
    CircularMap:SetPrimaryPartCFrame(workspace.CurrentCamera.CFrame*CFrame.Angles(math.rad(90),0,0)*CFrame.new(0,-10,0))
    FakeCam.CFrame = CFrame.new(HumanoidRootPart.Position + Vector3.new(0,10,0),HumanoidRootPart.Position)
end)

Hope this helped! :smiley:

9 Likes

Unless you’re updating the camera, stay away from RenderStepped. You can block the execution of render ticks since it runs before a frame and expensive code there can slow down performance on the client’s end. Ideally you should use Stepped which runs before physics are simulated.

7 Likes