Rotating part with CFrame not working in runservice.heartbeat loop

runservice.Heartbeat:Connect(function(step)
	--horizontal.CFrame = CFrame.lookAt(horizontal.Position, Vector3.new(target.Position.X, horizontal.Position.Y, target.Position.Z))
	--vertical.CFrame = CFrame.lookAt(vertical.Position, Vector3.new(target.Position.X, target.Position.Y, target.Position.Z))
	rotation.CFrame = rotation.CFrame * CFrame.Angles(.5,0,0)
end)

This doesn’t rotate the part, however doing:

while true do
       rotation.CFrame = rotation.CFrame * CFrame.Angles(.5,0,0)
       wait()
end

does rotate the part. Any ideas on why or how I could fix it to work in the heartbeat?

let me add that that in the heartbeat it rotates a little bit (maybe once?) and doesn’t continue. In the while loop, it keeps rotating.

Im guessing its because wait() is slower than heartbeat.

Also the angle 0.5 rads is quite a large jump so it could have the illusion of spinning 180 degrees.

Try using a smaller angle value and delta time math.deg(10)*step for heartbeat.

1 Like

this works, thankyou. i wasn’t aware you could do this

1 Like

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.