Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
1

How to add a model to the StarterCharacter's Head?

Asked by 4 years ago

im currently working on a Virus game but im not very experienced in welding and scripting so im using alot of videos to try and figure it out. I haven't been very successful in finding a way to weld this Virus part to the head of my startercharacter.

Ive named this model Handle and inside the model i have five mesh parts some containing particle emitters and scripts to rotate it around. I tryed making a weld and calling it HairAttachment but that didn't work ether. When i start the game i can move but the part drops from the sky is there a way i can fix this and keep it on my characters head. Any help would be really grateful

1 answer

Log in to vote
0
Answered by 4 years ago
Edited 4 years ago

Hello!

There is a scripting approach to this question, but also a non-scripting one. I'll write both just in case.

Non-scripting approach:

Alright so you have your model. Name doesn't matter. Put it in the StarterCharacter, make sure all parts within are unanchored. Create WeldConstraints that are inside each MeshPart in the model. In each one, set the properties Part0 to the StarterCharacter's head, and Part1 to the MeshPart that it's in. Position the model to the player's head, and you've got yourself a welded hat.

Scripting approach:

Put your hat in ServerStorage. Put the following code in a normal server script and put it in StarterPlayer>>StarterCharacterScripts.

hat = game.ServerStorage.Hat --whatever the name of your hat model is
hatHeightOffset = 0.3 --change this to how high you want the hat to be from the player's head. this value can be in the negatives.
hatClone = hat:Clone() --create a duplicate of the hat to put on the player
hatClone.Parent = script.Parent --put the hat in the player, which the script is currently in.
hatClone:MoveTo(Vector3.new(script.Parent.Head.Position.X, script.Parent.Head.Position.Y + hatHeightOffset, script.Parent.Head.Position.Z)) --position the hat

--- this next part will weld the hat ---

local children = hatClone:GetChildren()
for i, child in ipairs(children) do
    weld = Instance.new("WeldConstraint")
    weld.Parent = child
    weld.Part0 = child
    weld.Part1 = script.Parent.Head
end

I really hope this helps you, I put alot of time into my answer. The code should work, because I just tested it in a blank studio project.

Also if this helps you please accept my answer so that I can get reputation for my effort.

Anyway, hope this helps, and enjoy! :D

--ProqrammedGreen

0
thanks for the help QuantumPro_yt 7 — 4y
0
thanks QuantumPro_yt 7 — 3y
Ad

Answer this question