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

'Attempt to index nil with C0' How do I fix this error?

Asked by 2 years ago

I am trying to make the player's right arm point where the camera is looking but I keep getting the error saying "attempt to index nil with 'C0' " Here is the script:

local cam = workspace.CurrentCamera

local plr = game.Players.LocalPlayer

local char = plr.Character or plr.CharacterAdded:wait()
local hrp = char:WaitForChild("HumanoidRootPart")

local RightArm = char:FindFirstChild("RightArm", true)

local y = RightArm.C0.Y

game:GetService("RunService").RenderStepped:Connect(function()

    if RightArm then

        local camDirection = hrp.CFrame:ToObjectSpace(cam.CFrame).LookVector

        RightArm.C0 = CFrame.new(0,y,0) * CFrame.Angles(0, -camDirection.X, 0) * CFrame.Angles(camDirection.Y,0,0)

    end
end)

1 answer

Log in to vote
0
Answered by 2 years ago

You should use :WaitForChild instead of :FindFirstChild

local RightArm = char:WaitForChild("RightArm")
0
that cleared the error but now it's just an infinite yield. Is the right arm not defined maybe? DaGlizzzzzzyyyy 34 — 2y
0
I just checked that the character doesn't have a right arm. It has a RightLowerArm and RightUpperArm though so you can use one of those. JustinWe12 723 — 2y
Ad

Answer this question