Alright, so I'm trying to get an NPC to rotate to face the player when clicked.
This script exists within a ClickDetector found inside the NPC model.
"gyro" is a BodyGyro located within the torso of the NPC.
The properties of gyro are as follows:
D = 0
P = 3000
MaxTorque = inf,inf,inf
function clicked(Player)
if bool == false then
bool = true
local target = Player.Character.Torso
local root = script.Parent.Parent.Torso
local gyro = root.BodyGyro
local x = (target.Position.X)
gyro.CFrame = CFrame.new(root.Position, Vector3.new(target.Position.X, root.Position.Y, root.Position.Z))
wait(1.2)
bool = false
end
end
My problem is this: after maybe 10-15 seconds, regardless of whether or not I click on it, the BodyGyro will start spinning out of control and I have no idea why. Setting MaxTorque to 0,0,0 obviously fixes but in turn ruins the script itself.
I've also tried using Instance.new("BodyGyro") to spawn in a new object each time the script runs, but no luck. |