I have this script:
1 | local function LookAtMouse() |
2 | player.Character:WaitForChild( "Right Arm" ).CFrame = CFrame.new(player.Character:WaitForChild( "Right Arm" ).Position, mouse.Hit.p) |
3 | end |
When called, the character glitches.. Instead of ONLY the arm CFrame look at the mouse.Hit.p
, the whole body moves that direction for a milisecond and then goes back to normal. Is it because of the animations of moving or what?
This is a thing about player's characters. Since they have joints inside of them, when you move one part, all the parts move with them. A easy way to fix this is the following:
01 | local arm = player.Character:WaitForChild( "Right Arm" ) --get player's right arm |
02 | local newarm = arm:Clone() --clone it |
03 | newarm:ClearAllChildren() --get rid of all the joints in it |
04 | newarm.Anchored = true --anchor the part (cframe's dont work well with unanchored parts) |
05 | newarm.Name = "Rightt Arm" --name it something else |
06 | newarm.Parent = arm.Parent --put it in the plr's character |
07 | arm.Transparency = 1 ---make it non-visible |
08 |
09 |
10 | local function MoveTo(cframe) --this function will move the player's arm to the position |
11 | arm.CFrame = cframe |
12 | end |
Now, you could simply make the LookAtMouse like this:
1 | local function LookAtMouse() |
2 | MoveTo(CFrame.new(player.Character:WaitForChild( "Right Arm" ).Position, mouse.Hit.p)) |
3 | end |
If your not doing this already, this would need to be run in a while wait() do loop or game:GetService("RunService").RenderStepped loop for it to be constantly updating, I hope I could help you with your problem,
-REALTimothy0812