I'm currently coding a first person viewmodel. I'm trying to weld a brick to the camera's CFrame and weld all the other bricks (ex. arms, legs, gun) to that. It works fine for two arms, but when I add some more welds, my arm welds break.
local player = game.Players.LocalPlayer
local character = game.Workspace:WaitForChild(player.Name)
local cam = game.Workspace.CurrentCamera
local r = game:GetService("RunService")
wait(0.5)
-----------------------------------------------------------------------------
_G.weld = function(Part0, Part1, offset)
local weld = Part1:FindFirstChild("Weld")
if weld == nil then
weld = Instance.new("ManualWeld", Part1)
end
weld.Part0 = Part0
weld.Part1 = Part1
weld.C0 = offset
end
local function strip()
local allowed = {"Health", "Sound", "Head", "HumanoidRootPart", "Humanoid", "Torso", "Right Leg", "Left Leg"}
for i, v in pairs(character:GetChildren()) do
local destroy = true
for j, k in pairs(allowed) do
if v.Name == k then
destroy = false
end
end
if destroy == true then
v:Destroy()
end
end
character.Humanoid.Animator:Destroy()
end
local function createCamRef()
camRef = Instance.new("Part", character)
camRef.Name = "camRef"
camRef.CanCollide = false
end
local function createBodyPart(name, offset, size)
local newPart = Instance.new("Part", character)
newPart.Name = name
newPart.CanCollide = false
newPart.Size = size
r.RenderStepped:connect(function()
newPart.LocalTransparencyModifier = 0
end)
_G.weld(camRef, newPart, offset)
end
local bindCamRef = coroutine.wrap(function()
while true do
camRef.CFrame = cam.CFrame
r.RenderStepped:wait()
end
end)
-----------------------------------------------------------------------------
strip()
createCamRef()
createBodyPart("rightArm", CFrame.new(0.91988802, -1.18999767, -1.57000494, 0.982510507, 0.186142579, -0.00514012296, 0.00506633893, -0.0543143377, -0.998511076, -0.186144501, 0.981021106, -0.0543073677), Vector3.new(0.5, 2, 0.5))
createBodyPart("leftArm", CFrame.new(0.479999006, -1.36999798, -1.58000302, 0.973334193, -0.229391918, -5.92261415e-07, -0.0469625145, -0.199264362, -0.978819549, 0.224533245, 0.952718794, -0.204723582), Vector3.new(0.5, 2, 0.5))
bindCamRef()
