How to Rotate a Welded Part

My goal for this script is to have it rotate a mesh that is welded to a bunch of other meshes without rotating all of the meshes/parts that are welded to it.

So, there is a plow that is welded to the car automatically by A-Chassis. When my current code runs, it rotates the entire car instead of just the plow mesh.

Current Code:

local blade = script.Parent.Blade
local rotationAmount = 20
local rotationSpeed = 1

function rotateBlade()

	local currentRotation = 0

	while currentRotation < rotationAmount do
		blade.CFrame = blade.CFrame * CFrame.Angles(0, math.rad(rotationSpeed), 0)
		currentRotation = currentRotation + rotationSpeed
		wait()
	end
end

rotateBlade()

Video demonstrating what happens currently:

Please let me know how to do this or if it is even possible.

1 Like

I believe if you want to rotate a welded part you have to manipulate either the C0 or C1 properties of the weld rather than changing the CFrame of the part directly, which means you have to use a standard weld rather than a weld constraint

A post with a similar issue to yours has been posted before and has a solution set so perhaps that could help you out

This method doesn’t seem to be working for me and just glitches out the plow, or “Blade”.

Might mean you need to change around how you set the weld

Perhaps try something like this to change the rotation?

weld.C0 = weld.Part0.CFrame:ToObjectSpace(CFrame.new(weld.Part1.Position + weld.C1.Position) * CFrame.Angles(0, math.rad(rotationSpeed), 0))

Using a standard weld results in this happening to the plow.
image

You might need to change the value of C1 around to fix that, or change the rotation itself

This is what happens with this code,

local blade = script.Parent.Blade
local rotationAmount = 20
local rotationSpeed = 1
local weld = blade.ImportantWeld

function rotateBlade()

	local currentRotation = 0

	while currentRotation < rotationAmount do
		weld.C0 = weld.Part0.CFrame:ToObjectSpace(CFrame.new(weld.Part1.Position + weld.C1.Position) * CFrame.Angles(0, math.rad(rotationSpeed), 0))
		currentRotation = currentRotation + rotationSpeed
		wait()
	end
end

rotateBlade()

Thanks for the help, I was able to get it working with this code after changing around some things.

local blade = script.Parent.Blade
local rotationAmount = 20
local rotationSpeed = 1
local weld = blade.ImportantWeld

function rotateBlade()
	local currentRotation = 0

	while currentRotation < rotationAmount do
		weld.C0 = weld.C0 * CFrame.Angles(math.rad(rotationSpeed), 0, 0)
		currentRotation = currentRotation + rotationSpeed
		wait()
	end
end

rotateBlade()
1 Like

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