Making Player Look Towards Cursor

I need help, I made a script, what its supposed to do is make the players WHOLE body face the cursor however its not working i don’t know why can somebody please fix it?

I want it to look a bit like this


But i dont know how, can somebody help me?

5 Likes

You could make a function to call everytime the mouse moves

local plr = game.Players.LocalPlayer
local root = plr.Character.HumanoidRootPart
local mouse = plr:GetMouse()

mouse.Move:Connect(function()
 root.CFrame = CFrame.new(root.Position, 
 root.Position + mouse.Hit.LookVector)
end)
1 Like

Where should i put this? I dont know where it goes

1 Like

You could put this in a LocalScript in StarterCharacterScripts

2 Likes

As a seperate script? And delete the current one?

1 Like

robloxapp-20210621-0818410.wmv (1.6 MB)

2 Likes

That wouldnt work since this script will rotate the player towards the mouse on all axises, instead you only need to rotate it in one axis

2 Likes

this will rotate the character based on the mouse and make sure it doesn’t face up or down (exactly like the video tbh).

local runservice = game:GetService("RunService")
local HR = script.Parent:WaitForChild("HumanoidRootPart")
local mouse = game.Players.LocalPlayer:GetMouse()

runservice.RenderStepped:Connect(function()
	HR.CFrame = CFrame.new(HR.CFrame.Position, Vector3.new(mouse.Hit.p.X, HR.CFrame.Position.Y, mouse.Hit.p.Z))
end)

Also, put this inside of startercharacterscripts.

5 Likes

No that wouldnt work either because it will make the character look towards the mouse on all axises instead you need to use

And if you change the player hrp cframe it will freeze the player and disable its ability to move by teleporting it back to its old position instead create a BodyGyro inside players torso and set its cframe with this piece of code

runservice.RenderStepped:Connect(function()

BodyGyro.CFrame = CFrame.new(HR.CFrame.Position, Vector3.new(0, HR.CFrame.Position.Y, 0))

end)

+edit: you will need to adjust some of the body gyros values to your liking (D, P, MaxVelocity)

6 Likes

just try the script before even trying to call it “not working”.
robloxapp-20210621-0344582.wmv (903.8 KB)
There’s a video of me using the exact script I posted.

1 Like

It doesn’t Work For me Mine Doesn’t Move

It works! Thank you, I didn’t realize that, know for the future i can hopefully apply that to my games! robloxapp-20210621-1614168.wmv (1.8 MB)

1 Like

The script works for me too. Its good.

Maybe one of my scripts glitches it?

2 Likes

Well the final thing looks like this:

BodyGyro.MaxTorque = Vector3.new(0,10^5,0)
BodyGyro.CFrame = CFrame.new(plr.Character.HumanoidRootPart.CFrame.Position,Vector3.new(mouse.Hit.position.X, plr.Character.HumanoidRootPart.CFrame.Position.Y, mouse.Hit.Position.Z))

1 Like