BodyGyro CFrame Only Setting Once

Im trying to script a BodyGyro to make the characters body always face the direction of the mouse but when I use RunService to set the BodyGyros CFrame, it only sets once.

Script:

	---- Create Gyro ----
	local ShieldGyro = Instance.new("BodyGyro")
	ShieldGyro.Parent = char.HumanoidRootPart
	ShieldGyro.MaxTorque = Vector3.new(math.huge,math.huge,math.huge)
	ShieldGyro.D = 100
	ShieldGyro.P = 10000
	
	
		RunServ.Heartbeat:Connect(function()
			ShieldGyro.CFrame = CFrame.new(Vector3.new(0, 0, 0), Mouse.Hit.LookVector * Vector3.new(1, 0, 1))
		end)

How do I keep the Character facing the mouse at all times?

1 Like

Make sure the max force on the BodyGyro is set to 40000, 40000, 40000.

1 Like

Your CFrame is off, it’s looking from Vector3.new(0, 0, 0) to the mouse, so it won’t change if you’re far from the world origin.

The CFrame should be from the character to the mouse to create the correct rotation:

CFrame.new(
   character.HumanoidRootPart.Position * Vector3.new(1, 0, 1), -- Character position with 0 Y
   Mouse.Hit.p * Vector3.new(1, 0, 1)) -- Mouse position with 0 Y

I just tried this solution and It seems to do the same thing as my old code. Heres a video of what happens when I try this:

(When the shield is equipped the BodyVelocity is created). It only faces the mouses direction once when its activated and doesn’t change :confused:

Strange, is the Humanoid.AutoRotate false? That may be fighting your BodyGyro.

Also are you 100% sure the BodyGyro isn’t updating? Try printing the BodyGyro.CFrame in your heartbeat event to make sure it is changing with the mouse.

Alright so I tried the print and the body gyro IS updating and Humanoid.AutoRotate is always true. Heres a look at the updated code just incase:

RunServ.Heartbeat:Connect(function()
		ShieldGyro.CFrame = CFrame.new(char.HumanoidRootPart.Position * Vector3.new(1, 0, 1),Mouse.Hit.p * Vector3.new(1, 0, 1))
		print(ShieldGyro.CFrame)
		end)
	end)

Sorry I worded it weird earlier! I met that Humanoid.AutoRotate should be false while you try to control a character’s direction.

If that doesn’t work I don’t know what is keeping the BodyGyro from working. You could double check to make sure you are giving the right CFrame by setting the character’s CFrame directly instead.

Other than that I’m out of ideas, I hope you figure it out one way or another!

Hey so thanks for all the help but I finally realized the solution and honestly feel a bit dumb :sweat_smile:. I was trying to set the BodyGyros CFrame through the server using a remote event after passing through the Mouse, and since the event is only fired once, Mouse.Hit.p will always stay the same. So Im making and changing the BodyGyros CFrame through LocalScript now. But thanks again for all the help :smiley:.