How to make the player constantly face a part

I am making a soccer game and I am trying to make it so when the player presses “G” their body will be facing the ball until G is released.

UserInputService.InputBegan:connect(function(inputObject, gameProcessedEvent)
	if inputObject.KeyCode == Guard then
		ball = court:FindFirstChild("Ball")
		local rootPart = player.Character:FindFirstChild("UpperTorso")
		while true do
			rootPart.CFrame = CFrame.lookAt(rootPart.Position, ball.Position)

This is what I have so far and it technically works but the issue is every time the while loop runs it changes the direction the player is facing which makes it look very glitchy. Wondering if there was a way to make this a lot smoother.

1 Like

Have you tried using the Camera Subject property?

I have never heard of this what does it do

1 Like

So. This is something that the camera focuses on. The normal camera subject is the Humanoid.

Here is some more info: Camera | Roblox Creator Documentation

It looks like that just changes the camera but I am not worried about the camera I just want to rotate the character, or does this rotate the player.

ohhh. You want the player to face the ball.

1 Like

yea like as they move around I want their body to keep looking at the direction of the ball.

Have a read on CFrame’s. That way, you should be able to make the player look in a certain direction (The ball)

making it so the player faces the ball is something I already figured it, my issue is how can I do that constantly without it looking glitchy

Using LookVector Might help, Alvinblox made a video on CFrame and LookVector,

I suggest you look into using a BodyGyro, or a AlignPosition joint. Body gyro would be my recommend, as they are easier to use, however they have been deprecated.

Good idea, but look vector is for getting the vector3 of what a part is “looking” at, specifically the vector3 position at the front face of the part, which is not really for this use case.

1 Like