Body Gyro broke for an unknown reason

Making a auto-rotating automatic gun but it doesn’t align with the target (though the steering engine uses virtually the same code and works???)
I tried changing the order of arguments within the CFrame configuration, the Torque, the density of implicated objects, but all failed.
No errors are to be found within the output, and the torque changed correctly as well.
Does anyone know the answer?

for i,v in pairs(script.Parent:GetChildren()) do
			if v:FindFirstChild("Gun") then
				print("Changing gyro (lol we're not)"),player.Position),1000,0)
		end uses the parts lookvector to look at the target position.

To visualize we can use Alvinblox’s dummy example, where the face is on the front of the part.

So make sure your turrets v.Gun.Base is orientated properly with the gun nozzle in the look vector of the part.

i know that, i used it for other things and it worked
but for some reason not here
is it maybe due to the fact i already used a bodygyro for the car under it?
it’s attached using a hingeconstraint
(though then again, it wouldn’t explain why it moved using a BodyAngularVelocity)

I have a few questions about your setup.

  1. Is this a Local or Server script?
  2. script.Parent == the Gun?
  3. Are any of the objects connected to Gun.Base Anchored?
  4. Have you tried setting the MaxTorque on all Vectors?
  5. Does your print code Changing gyro (lol we're not) actually print?
  6. Is your For loop repeated by some other code, or does it only run once when the script starts?
  7. Have you validated player exists
  1. server. I may be very stupid but i know that at least
  2. no it’s the tank folder, but the result remains the same
  3. no, checked that
  4. haven’t tried that yet, give me a minute
  5. it does
  6. repeated (indirectly)
  7. it does

i tried 4) and it produced inconclusive effects; the turrets turned slowly but failed to get to the right angle, and produced inconsistent results

you would be surprised how many times I’ve done this. :smiley:

Classical Debug time!

for i,v in pairs(script.Parent:GetChildren()) do
	if v:FindFirstChild("Gun") then
		local from = v.Gun.Base.Position
		local too = player.Position
		local dir = (too-from)
		print("From",from, "Too",too,"Dist",dir.Magnitude)

		local p ="Part",workspace)
		p.Anchored = true
		p.CanCollide = false
		p.Size =,0.5, dir.Magnitude)
		p.CFrame =,too)
		p.Transparency = 0.75
		p.BrickColor = BrickColor.Red()
		game.Debris:AddItem(p, 1)

		v.Gun.Base.BodyGyro.CFrame = from, too )

weirdly enough the trajectories fully align with the centers of the divisions, but the gyros don’t…

that means it’s a physical issue, isn’t it?

That is odd.

Have you tried applying this code to a singular part by itself with a gyro to check if the issue is with the Gyro, or the mechanisms for the Tanks?

found the fix, i parented the gyro to the part above, and it worked
thanks for the help

1 Like