Unable to find player's shoulders when using mouse.move?

so i have a script that uses renderstep, it works fine with no errors. but when i switched it to mouse.move because i think that would increase the performance of gameplay, it shows an error like this:

Players.foxnoobkite.Backpack.Tool.LocalScript:8: attempt to index nil with 'WaitForChild'

anyway heres the script, before i had mouse.move with run.renderstep

local run = game:GetService("RunService")
local tool = script.Parent
local equipped = false
local Player = game.Players.LocalPlayer
local mouse = Player:GetMouse()
local char = Player.Character

local DefaultRightArm = char:WaitForChild('Torso'):WaitForChild('Right Shoulder').C0
local DefaultLeftArm = char:WaitForChild('Torso'):WaitForChild('Left Shoulder').C0

tool.Equipped:Connect(function()
	equipped = true
end)

tool.Unequipped:Connect(function()
	equipped = false
	char:WaitForChild('Torso'):WaitForChild('Right Shoulder').C0 = DefaultRightArm
	char:WaitForChild('Torso'):WaitForChild('Left Shoulder').C0 = DefaultLeftArm
end)

mouse.Move:Connect(function()
	mouse.TargetFilter = game.Workspace
	if equipped == true then
		local rightX, rightY, rightZ = char:WaitForChild('Torso'):WaitForChild('Right Shoulder').C0:ToEulerAnglesYXZ()
		char:WaitForChild('Torso'):WaitForChild('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:WaitForChild('Torso'):WaitForChild('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)
2 Likes

Hi mouse.Move might not be enough as, player can move their character and not move their mouse,The error means either Torso did not exist, Or Character did not exist

1 Like

oh is there a better alternitave that works? i think running mutiple rendersteps will cause performance problems, i am not sure though.

1 Like

I use a spawn() function and heartbeat while loop

1 Like

are these better at performances realitive to renderstep? cause i am worried that the player might have a lot of tools and a lot of things are gonna be running

1 Like

Yes, But You could stop the loop if equibbed is false

1 Like

hmm i tried while loop and still the same error???

local run = game:GetService("RunService")
local tool = script.Parent
local equipped = false
local Player = game.Players.LocalPlayer
local mouse = Player:GetMouse()
local char = Player.Character

local DefaultRightArm = char:WaitForChild('Torso'):WaitForChild('Right Shoulder').C0
local DefaultLeftArm = char:WaitForChild('Torso'):WaitForChild('Left Shoulder').C0

tool.Equipped:Connect(function()
	equipped = true
end)

tool.Unequipped:Connect(function()
	equipped = false
	char:WaitForChild('Torso'):WaitForChild('Right Shoulder').C0 = DefaultRightArm
	char:WaitForChild('Torso'):WaitForChild('Left Shoulder').C0 = DefaultLeftArm
end)

tool.Equipped:connect(function()
	while equipped do
	mouse.TargetFilter = game.Workspace
		local rightX, rightY, rightZ = char:WaitForChild('Torso'):WaitForChild('Right Shoulder').C0:ToEulerAnglesYXZ()
		char:WaitForChild('Torso'):WaitForChild('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:WaitForChild('Torso'):WaitForChild('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)

It means, Either character is nil, Or the torso i nil, Is the script in starter player?

no. it is a local script in a tool