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