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

HumanoidRootPart is not a valid member of Character?

Asked by 4 years ago

So I have a mini map, But it should work, But for some reason in the output its saying that HumanoidRootPart isn't a valid member of Character? Here is the Local script:

local CircularMap = game.ReplicatedStorage.CircularMap
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,-3))
    FakeCam.CFrame = CFrame.new(game.Players.LocalPlayer.Character.HumanoidRootPart.Position + Vector3.new(0,10,0), game.Players.LocalPlayer.Character.HumanoidRootPart.Position)
    game:GetService("RunService").RenderStepped:Wait()
end

Also, if you wondering where i says HumanoidRootPart is on line 14, Thanks.

2 answers

Log in to vote
1
Answered by 4 years ago
Edited 4 years ago

An easy way to fix this problem is to listen for the character until it loads in:

game.Players.LocalPlayer.CharacterAdded:Wait()

You can then check to see if the HumanoidRootPart exists:

if game.Players.LocalPlayer.Character.HumanoidRootPart then

An easy but pretty good solution to your problem.

Ad
Log in to vote
-1
Answered by
OBenjOne 190
4 years ago

I often had this same problem with the humanoid. I think the problem is that the player loads before the character does. So just add a line to wait until the character loads to run your script:

  repeat wait() until game.players.localplayer.character ~= nil and game.players.localplayer.character:FindFirstChild("HumanoidRootPart")  ~= nil
0
If i mis-capitalized or misspelled something it is because i am on a phone OBenjOne 190 — 4y
0
-1 for suggesting polling over events. User#24403 69 — 4y
0
Ok but it would have worked OBenjOne 190 — 4y

Answer this question