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)
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
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