Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
✓ ANSWER ACCEPTED

Create a movable part on the player's head?

1 answer

✓ Accepted answer

You probably used regular Welds, or ManualWelds. If you want the part to spin freely, you need another joint type. While Joints are getting outdated and ROBLOX now uses Contstraints, it's neat to use those. Let's use a HingeConstraint.

Constraints work like joints, except you can define attachment points on bricks, and depending on the Constraint Type used, the Parts get moved together, glued together, hinged together, or even put together with a Rod.

To make a constraint work, we first need Attachments. Define those inside partA and the player's head:

local partA = game.Workspace.PartA
local attachmentA = Instance.new("Attachment", partA)
attachmentA.Position = Vector3.new(0, -.5, 0)
 
local phead = game.Workspace.Player1.Head
local attachmentB = Instance.new("Attachment", phead)
attachmentB.Position = Vector3.new(0, .5, 0)

When initializing Attachments, we need to define Positions, where the Attachments will be. Using .5 and -.5 creates attachments ontop of the head (half a brick higher from the middle of the head brick) and below the brick (half a brick lower from the brick's middle point). Next, we actually have to connect these. There are many types of constraints, as I stated before, and HingeConstraint is just perfect, as it lets the Part rotate freely at all times. How do we initialize one?

local hingeConstraint = Instance.new("HingeConstraint", partA)
hingeConstraint.Attachment0 = attachmentA
hingeConstraint.Attachment1 = attachmentB

Now we have a neat HingeConstraint holding together the pieces. But what if its.. weird and spins in the wrong direction? You can change the rotation of a constraint easily.

attachmentA.Rotation = Vector3.new(0, 90, 0)

Choose this Rotation feature to your needs.

And there you go, bye bye old, useless welds, because we just made Constraints happen!

sorry for actually explaining Constraints ;) you could've just used a Hinge joint, which is the weld version of a HingeConstraint.

1 comment

0

Oh, I forgot one thing! When using Constraints in your place, if you haven't already, you have to set "PGSPhysicsSolverEnabled" in Workspace to true. :o

This discussion is preserved as it was. New answers, comments, and votes are closed.