So i have a part that spins, its welded to a basepart with a weldconstraint, but there is an issue
The part is tilted, and when rotating it spins weirdly
How it’s supposed to spin
How it spins
Code:
local partRotation = part.Orientation.Y
while status do
partRotation += 3
part.Orientation = Vector3.new(part.Orientation.X, partRotation, part.Orientation.Z)
task.wait(cooldown)
end
I tried using CFrame.Angles(), it works but spinning it like that also rotates the welded basepart.
Instead of changing the Orientation property, you should switch it for a rotation matrix (CFrame for short)
Here’s how you can manipulate a part’s CFrame:
-- variables
local part = script.Parent
local ROTATE_INCREMENT = math.rad(4)
local ROTATE_SPEED_MODIFIER = 1/60
-- functions
local function spin()
part.CFrame *= CFrame.Angles(0, ROTATE_INCREMENT, 0)
end
while (true) do
spin()
task.wait(ROTATE_SPEED_MODIFIER)
end
The function spin() is responsible for actually rotating the part. It multiplies the current part’s CFrame by a new CFrame labelled CFrame.Angles(0, ROTATE_INCREMENT, 0).
The conditional loop underneath the function is what will actually invoke the spin() function every x seconds - in this case x being ROTATE_SPEED_MODIFIER (A variable seen at the top)
ROTATE_SPEED_MODIFIER - Is the speed at which the conditional loop iterates at.
ROTATE_INCREMENT - Is the amount the part will orientate by every time the function spin() is invoked.
Additionally, you said you’ve welded parts to the main part. Make sure to un-anchor the welded parts and set the variable part to the main part.
Ah, I see. Well I’m yet to learn about the Tool class and its entirety. I could suggest using an Animation for the spinning part, or even an AlignPosition mixed with an AlignOrientation .
Sorry I couldn’t help, I wish you the best of luck, hopefully somebody smarter than me can assist you.