Attempt to index nil with torso

Hello, I have a local script that is located in a tool. But a error keeps popping out saying it can’t find the torso… I am on R6 and heres the script

local run = game:GetService("RunService")
local Tool = script.Parent
local Player = game.Players.LocalPlayer
local Mouse = Player:GetMouse()
local char = Player.Character
equipped = false
local Character = Player.Character
Tool.Equipped:Connect(function()
	equipped = true
end)
Tool.Unequipped:Connect(function()
	equipped = false
end)

Mouse.Move:Connect(function()
	if equipped then
		local rightX, rightY, rightZ = char.Torso["Right Shoulder"].C0:ToEulerAnglesYXZ()
		char.Torso["Right Shoulder"].C0 = (char.Torso["Right Shoulder"].C0 * CFrame.Angles(0, 0, -rightZ)) * CFrame.Angles(0, 0, math.asin((Mouse.Hit.p - Mouse.Origin.p).unit.y))

		local leftX, leftY, leftZ = char.Torso["Left Shoulder"].C0:ToEulerAnglesYXZ()
		char.Torso["Left Shoulder"].C0 = (char.Torso["Left Shoulder"].C0 * CFrame.Angles(0, 0, -leftZ)) * CFrame.Angles(0, 0, math.asin((-Mouse.Hit.p - -Mouse.Origin.p).unit.y))
	end
end)
1 Like

The script didn’t find the torso so it threw that error.

A solution would be to wait for the torso to make sure it exist:

local Torso = char:WaitForChild("Torso")

Also you are defining the player’s character twice:
local char = Player.Character and local character = Player.Character

1 Like

local char = player.Character or player.CharacterAdded:Wait()

3 Likes

The script didn’t find the character. It’s saying that you are trying to index nil with torso. That means the same as nil.torso

1 Like