Help with bodygyros

So, I’ve always been confused with BodyGyros as their not straight forward. I got some help to rotate an object using this code below. I have been trying this on another part, Maxtorque at inf, D at 250 and P at 3000. It seems to rotate only 90 degrees or just not at all. Any help?


local part = script.Parent.Parent.StageThree.ThirdStageFuelTank
local bodyGyro = part.BodyGyro
local BodyVelocity = part.BodyVelocity

local x = 0

x += 0.05

repeat
	bodyGyro.P = bodyGyro.P + x
	wait(0.5)
until( bodyGyro.P == 1000 )

wait(5)
bodyGyro.CFrame *= CFrame.Angles(math.rad(45), 0, 0) ```
local part = script.Parent.Parent.StageThree.ThirdStageFuelTank
local bodyGyro = part.BodyGyro
local BodyVelocity = part.BodyVelocity
local x = 0
while true do wait(0.1)
x += 0.05
end
repeat
	bodyGyro.P = bodyGyro.P + x
	wait(0.5)
until( bodyGyro.P == 1000 )

wait(5)
bodyGyro.CFrame *= CFrame.Angles(math.rad(45), 0, 0)

wont work lol. while loop will go on forever

if that didnt work try this

local part = script.Parent.Parent.StageThree.ThirdStageFuelTank
local bodyGyro = part.BodyGyro
local BodyVelocity = part.BodyVelocity
bodyGyro.CFrame=part.CFrame
local x = 0
while true do wait(0.1)
x += 0.05
end
repeat
	bodyGyro.P = bodyGyro.P + x
	wait(0.5)
until( bodyGyro.P == 1000 )

wait(5)
bodyGyro.CFrame *= CFrame.Angles(math.rad(45), 0, 0)

then try this

local part = script.Parent.Parent.StageThree.ThirdStageFuelTank
local bodyGyro = part.BodyGyro
local BodyVelocity = part.BodyVelocity
bodyGyro.CFrame=part.CFrame
local x = 0
repeat
     x += 0.05
until bodyGyro.P == 1000
repeat
	bodyGyro.P = bodyGyro.P + x
	wait(0.5)
until bodyGyro.P == 1000 
wait(5)
bodyGyro.CFrame *= CFrame.Angles(math.rad(45), 0, 0)

are you trying to spin a thing forever then use BodyAngularVelocity as its much simpler…

no… and that code is just not going to work.

I just need it to rotate to a certain angle. Preferably the angle I put in is in 360 degrees. Say I put 45, it rotates 45 degrees of 360.

you could use hinge constraint and actuator type as servo and you can put the target angle this method is much less compllicated,the body gyro :nauseated_face::face_vomiting:

It doesn’t look like you’re changing the CFrame within loops. Body gyros only move towards their CFrame, so if you want it to keep rotating it you’ll have to keep changing the CFrame or use a body angular velocity.

1 Like

This is why for loops exist too. Plus you can stop a while loop if the statement is false.

turned out to be as simple as


local part = script.Parent

local bodyGyro = Instance.new("BodyGyro")

bodyGyro.Parent = part

wait(5)

bodyGyro.CFrame *= CFrame.Angles(math.rad(-45), 45, 0)