[HELP!] - How do I rotate WELDED parts with Script?

Hello guys, I want to rotate the wheels of the hover, but they are welded to the hover and the hover is welded to the player. How do I do this?

3 Likes

you can rotate welded parts using the CFrame property of the parts. The CFrame property represents the position and orientation of a part in 3D space.

To rotate a part, you need to create a new CFrame that represents the desired orientation, and then assign it to the part’s CFrame property.

Here’s an example of how you could rotate the wheels of a hover while the hover is welded to the player:

local player = game.Players.LocalPlayer
local hover = player.Character.Hover
local wheel1 = hover.Wheel1
local wheel2 = hover.Wheel2

local rotationAmount = math.rad(45)
local rotationMatrix = CFrame.new(0,0,0, math.cos(rotationAmount), 0, -math.sin(rotationAmount), 0, 1, 0, math.sin(rotationAmount), 0, math.cos(rotationAmount))

wheel1.CFrame = wheel1.CFrame * rotationMatrix
wheel2.CFrame = wheel2.CFrame * rotationMatrix

In this code, player is a reference to the local player, hover is a reference to the hover object, and wheel1 and wheel2 are references to the wheels. The rotationAmount variable holds the amount of rotation in radians, and the rotationMatrix variable holds a CFrame that represents the rotation. Finally, the CFrame of each wheel is updated by multiplying it with the rotationMatrix .

1 Like

Assuming you use the weld object for welding instead of weldConstraint, just set weld.C1 to weld.C1 * CFrame.Angles(math.rad(1),0,0) for one degree of rotation.

It doesn’t work, when the wheels are rotated, the hover is also rotated. I only want the wheels to rotate, even though they are welded.

I use weld constraint all the time

Is there a reason you can’t use a hinge constraint? Welds are made specifically to maintain the same CFrame of one part, relative to another part, not for parts that need to be moving relative to one another

Hinge Constraints use attachments, and they are difficult to set up in a Script.

for i, wheel in pairs(physicalplayer.Vehicle.Wheels:GetChildren()) do

		local WheelPosition = WheelPositions:FindFirstChild(wheel.Name.."Position")
		print(WheelPosition)
		wheel.Position = Body.Position + WheelPosition.Value
		wheel.Size = WheelSize.Value

		local weld = Instance.new("WeldConstraint",wheel)
		weld.Part0 = wheel
		weld.Part1 = Body

	end
1 Like

Couldn’t you just add the attachments to the models you’re cloning, set up their positions and orientations in studio, then create the hinge in place of creating the weld?

I found here another possible solution in this topic, but I dont understand what CFrame:Inverse() does…

Rotating a Welded Part? - Help and Feedback / Scripting Support - DevForum | Roblox