Weird shaking when I hover the right arm with my mouse

Hi! I wrote a code that basically makes a player rotating/bending towards the mouse position. Everything works great except of one Bugg, weird shaking when I hover the right arm with my mouse. Here is a video: robloxapp-20200727-2305496.wmv (2.3 MB) and here is my script:

local plr =  game:GetService("Players").LocalPlayer
local ms = plr:GetMouse()
local waist = plr.Character:FindFirstChild("Waist", true)
local defPos = waist.C0.Y
local root = plr.Character:FindFirstChild("HumanoidRootPart")
local cf, v3 = CFrame, Vector3
game:GetService("RunService").RenderStepped:Connect(function()
	print(root.CFrame.p)
    ---------- ROTATING OF WAIST ---------
	local dif = (root.CFrame.p - ms.Hit.p) 
	local look = (root.CFrame.upVector)
	local angle = math.acos((dif:Dot(look) / dif.Magnitude * look.Magnitude))
	waist.C0 = cf.new(0, defPos, 0) * cf.Angles(angle - math.pi / 2, 0, 0)
    -------- ROTATING OF A PLAYER ----------	
    local direction = (ms.Hit.p - root.Position) * v3.new(1, 0, 1)
	root.CFrame = cf.new(root.Position, root.Position + direction)
end)

Thanks for help!

1 Like

I suspect that the player will try to move in the direction of the arm, but as he moves there the mouse moves to the back again:


Maybe try to add something like this in the code:

if ms.Target.Parent:FindFirstChild("Humanoid") and ms.Target ~= nil then -- Check if mouse is on player
        print("Mouse on player")
    else
        local direction = (ms.Hit.p - root.Position) * v3.new(1, 0, 1)
    	root.CFrame = cf.new(root.Position, root.Position + direction)
    end
    end)

Thanks, I simply used TargetFilter, to filter a player and a gun.

1 Like