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

Why does the HumanoidRootPart only seem to exist in the Studio?

Let's just start by showing my code:

local player = game.Players.LocalPlayer
local char = player.Character
if not char or not char.Parent then
    char = player.CharacterAdded:wait()
end

local model = Instance.new("Model", game.Workspace)
local rightArm = Instance.new("Part", model)
rightArm.Size = Vector3.new(.6,.7,3.5)
rightArm.Material = "Metal"
rightArm.BrickColor = BrickColor.new("Pastel brown")

local leftArm = Instance.new("Part", model)
leftArm.Size = Vector3.new(.6,.7,3.5)
local Humanoid = Instance.new("Humanoid", model)
leftArm.Material = "Metal"
leftArm.BrickColor = BrickColor.new("Pastel brown")

local RightWeld = Instance.new('Weld', rightArm)
RightWeld.Part0 = rightArm
RightWeld.Part1 = char.HumanoidRootPart
RightWeld.C0 = CFrame.new(-1.2,-.4,0)*CFrame.fromEulerAnglesXYZ(math.rad(10),math.rad(-20),math.rad(-5))

local LeftWeld = Instance.new('Weld', leftArm)
LeftWeld.Part0 = leftArm
LeftWeld.Part1 = char.HumanoidRootPart
LeftWeld.C0 = CFrame.new(1.2,-.4,0)*CFrame.fromEulerAnglesXYZ(math.rad(10),math.rad(20),math.rad(5))

Yeah it might look intimidating and large but it's really simple code, all it does is creates two local fake arms, welds them to the HumanoidRootPart and offsets them to fit in the cameraview. And it works flawlessly when I play it in the studio (which has FE turned on, btw). But when it's uploaded to a game it just stops working, giving the following error: "HumanoidRootPart is not a valid member of Model" and then references to line 21.

What did I do wrong and why does it work in Studio? What is different when it comes to the real thing? And most importantly: How do I fix it?

Help would be greatly appreciated, thanks! :D

1 comment

0

Try char:WaitForChild("HumanoidRootPart")

1 answer

✓ Accepted answer

You need to use WaitForChild().

Im on phone so I can't copy/paste your code just to change that line, but just change char.HumanoidRootPart to char:WaitForChild("HumanoidRootPart")

1 comment

0

Thanks, I'll try that!

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