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

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

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

You should use :WaitForChild instead of :FindFirstChild

local RightArm = char:WaitForChild("RightArm")

2 comments

0

that cleared the error but now it's just an infinite yield. Is the right arm not defined maybe?

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.

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