Character won't follow mouse?

  1. What do you want to achieve? Keep it simple and clear!
    I want the character to look at the mouse.
  2. What is the issue? Include screenshots / videos if possible!
    Whenever I run my script it just hits me with "attempt to index nil with ‘Character’.
  3. What solutions have you tried so far? Did you look for solutions on the Developer Hub?
    I read the “Facing Toward a Point” section on Understanding CFrames.
    Link: CFrames | Documentation - Roblox Creator Hub

I also read this post on the devforum but nothing made my character look in the direction of my mouse.
Link: Character follow mouse not working as intended?

I only have a normal script in the workspace, this is the code inside of it.

wait(2)

local player = game.Players.LocalPlayer
local Character = player.Character
local Mouse = player:GetMouse()

while wait() do
	local StartPosition = Character.HumanoidRootPart.Position
	local TargetPosition = Mouse.Hit.p
	
	Character.HumanoidRootPart.CFrame = CFrame.new(StartPosition, TargetPosition)
end

This only works in a local script, so put it inside player character scripta

1 Like

Oh, I didn’t realize that, it works now, thank you.

Now there is a new issue, the entire character model follows the mouse, not just the torso, anyway to fix this?

You are moving the humanoid root part and not the torso, hence the entire body

My code now looks like this but my character is still freaking out for some reason.

wait(2)

local player = game.Players.LocalPlayer
local Character = player.Character
local Mouse = player:GetMouse()

while wait() do
	local StartPosition = Character.UpperTorso.Position
	local TargetPosition = Mouse.Hit.p
	
	Character.UpperTorso.CFrame = CFrame.new(StartPosition, TargetPosition)
end

I think that’s because animations still play even when you are Cframinh

Is there any possible way to fix that?

Try looking at this thread, someone else try doing the same thing as you:

Edit: tldr use motor6ds joint C0 for character rig rotation

1 Like

Alright I’ll try that, see if it works, I’ll post again if it does.

I found the twitter post going down the rabbit hole on that link and that solved my problems.

1 Like