Rotating a part with CFrame causes it to rotate in every axis instead of only one

That’s the script I’m using to rotate a part on its X axis. The problem is that this is affecting the part’s orientation in every axis.

local function spinRotatingPart(part, timeToFullyRotate)
	while true do
		local changePerSpin = timeToFullyRotate/0.03

		part.CFrame = part.CFrame * CFrame.Angles(0,math.rad(1),0)
		wait()
	end
end

Thanks! :happy1:

change starting from this column “CFrame.Angles(0,math.rad(1),0)” to
“CFrame.Angles(math.rad(1),0,0)”

it nows swings in one axis, but not the right one.

what axis is it on then?

char limitttttttttttttttttttttt

Y axis instead of x. I just noticed that making this script:

local TurningSpeed = 10 -- You can change how fast you want the part to spin here

while true do
    script.Parent.CFrame = script.Parent.CFrame * CFrame.Angles(0, math.rad(TurningSpeed), 0)
    wait(0.01) -- This determines how often the part turns (Updates the part to turn every 0.01 seconds, The lower the number the better transition)
end

makes it spin in the right direction

I think I found why this happens. I’m using collection service and that may be screwing things up. I think that a part Is being rotated 2 times because putting a single script inside of the part makes it work perfectly fine.

You may like this one. Lets you set the rotation and rotates with a tween.

--local script, test script
local player=game:GetService("Players").LocalPlayer
local character=player.Character or player.CharacterAdded:Wait()
local humanoid=character:WaitForChild("Humanoid")

task.wait(3) --> so we can see it happen.

local desiredAngle=90 --> set as you will
local desiredAngleRad=math.rad(desiredAngle)
local currentRotation=character.PrimaryPart.CFrame
local newRotation=currentRotation*CFrame.Angles(0,desiredAngleRad,0)
local tweenInfo=TweenInfo.new(0.2, Enum.EasingStyle.Linear, Enum.EasingDirection.Out)
local rotateTween=game:GetService("TweenService"):Create(character.PrimaryPart,tweenInfo,{CFrame=newRotation})
rotateTween:Play()

This is a modified version of a script I use to turn the player towards where the mouse just clicked.
humanoid is in the mix here to make sure we get a fully loaded character before we mess with it. The task.wait() isn’t needed, it is there so we get a pause and then can see it turn …

my bad, I had multiple scripts rotating the same part… I fixed it! :happy1:

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