Apparently body parts from the Character are nil?

So, I’m trying out a little thing that makes your arm follow your mouse, but in each script, body parts addressed from Player.Character are nil. I don’t understand what’s wrong, but Roblox says that the HumanoidRootPart is nil. “Players.AbsurdAwesome101.PlayerScripts.LocalScript:3: attempt to index nil with ‘HumanoidRootPart’” keeps happening. I don’t know if it’s a problem with the script or just an error, but it’s quite frustrating.
This is the script:

local Camera = workspace.Camera
local char = game.Players.LocalPlayer.Character
local HRP = char.HumanoidRootPart
local rightShoulder = char.Torso["Right Shoulder"]
local asin = math.asin
local YOS = rightShoulder.C0.Y
local RunService = game:GetService("RunService")
local CFNew, CFAng = CFrame.new, CFrame.Angles
RunService.RenderStepped:Connect(function() 
	local Direction = HRP.CFrame:toObjectSpace(Camera.CFrame).lookVector
	rightShoulder.C1 = CFNew(0, YOS, 0) * CFAng(3 * math.pi/2, 0, math.pi) * CFAng(0, 0, -asin(Direction.x)) * CFAng(-asin(Direction.y), 0, 0)
end)
2 Likes

Try this

local Camera = workspace.Camera
local char = game.Players.LocalPlayer.Character or game.Players.LocalPlayer.CharacterAdded:Wait()
local HRP = char:WaitForChild("HumanoidRootPart")
local rightShoulder = char:WaitForChild("Torso")["Right Shoulder"]
local asin = math.asin
local YOS = rightShoulder.C0.Y
local RunService = game:GetService("RunService")
local CFNew, CFAng = CFrame.new, CFrame.Angles
RunService.RenderStepped:Connect(function() 
	local Direction = HRP.CFrame:toObjectSpace(Camera.CFrame).lookVector
	rightShoulder.C1 = CFNew(0, YOS, 0) * CFAng(3 * math.pi/2, 0, math.pi) * CFAng(0, 0, -asin(Direction.x)) * CFAng(-asin(Direction.y), 0, 0)
end)

It’s good practice to use :WaitForChild() so that way your script(s) wait for things to load.

thanks, the script didnt even work anyway but thanks for helping

You’re welcome. Quick question, what is the “Right Shoulder?” Are you referencing to an artificial part you made or are you talking about the Right Upper Arm?