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

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

Asked by 6 years ago

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

0
Try char:WaitForChild("HumanoidRootPart") theCJarmy7 1293 — 6y

1 answer

Log in to vote
0
Answered by
Amiaa16 3227 Moderation Voter Community Moderator
6 years ago

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")

0
Thanks, I'll try that! LetsGoRobloxia 7 — 6y
Ad

Answer this question