Why isn't my hat working

So I am making a game which involves the players spawning in as a custom character. Everything is working fine except for the hat I made which is a helmet that completely covers the players head. It is made up of a bunch of unions and grouped together. Whenever I test the game the hat completely falls apart. I made every surface of the hat welded and if I anchor it then the character can’t move with it on. Anyone know how I might be able to fix this?

1 Like

Have you tried using a weld constraint on every part in the group linked to a single primary part? Make sure that your helmet model has this primary part. If you need further help, I could help you understand how a script could most likely solve this problem. Also further detail in your explanation (like pictures etc) would be nice!

So you could easily use a script that creates new weld constrain instances so that the helmet stays together. Models have this nifty thing called a “PrimaryPart” which you can set to any BasePart inside said model. Make sure that you have your primary part set!

To create a simple script to achieve this, first we would want to locate the model in question:

local model = game:GetService("Workspace").ModelName --Make sure that this location is where your model is!

Remember that no other part in Workspace should have your models name.

Now that we have the location set, we want to use a for loop to go through the model and find everything inside of it:

for index,object in pairs(model:GetDescendants()) do --:GetDescendants returns everything that is the child of the object you provided

With this loop, because we don’t know what type of object it will be returning, we want to make sure it is a BasePart, and we can easily use :IsA() to check if Is A BasePart

if object:IsA("BasePart") then --This will make sure that we only apply the constraint to objects that are a base part, because we don't need to apply a constraint for decals, lights, models, etc.

Now that we have this down, it’s time to actually create the weld constraints. To do this we can use Instance.new() which creates us whatever we want to create. When said instance is created, we need to set the parent of that object.

local weld = Instance.new("WeldConstraint") --Bada bing bada boom! We've got a weld!
weld.Parent = model.PrimaryPart --It doesn't really matter what you set the parent of the weld to. You could set it to the primary part or the object on the loop.

We’re almost done! Now we need to set what the weld constraint is welding together! These are known as Part0 and Part1

weld.Part0 = model.PrimaryPart
weld.Part1 = object --Remember, object is what object the loop is currently on.

Tada! You’re all done! So, here is what you should have all together:

local model = game:GetService("Workspace").ModelName

for index,object in pairs(model:GetDescendants()) do
if object:IsA("BasePart") then
local weld = Instance.new("WeldConstraint") 
weld.Parent = model.PrimaryPart 
weld.Part0 = model.PrimaryPart
weld.Part1 = object

Not sure why it isn’t letting me indent… Instead of indenting in sent the post unfinished, nice.

Now you can insert this into your command line and you should be good to go!

Let me know if you need more help :slight_smile:

Helpful Links:


1 Like