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

How do I attach objects to a player model?

Hi everyone, I'm currently trying to attach some models to my StarterCharacter model for a game I'm working on. To be completely honest, I have no idea what to do. I tried using weld constraints but that didn't work, as this happened: https://imgur.com/a/qzrJl63

What do I do to solve this? (the helmet, gloves, and chest piece are what I am trying to attach, as seen in the picture)

1 comment

0

When you used the weldconstraint, were the models you were trying to attach anchored or not?

1 answer

✓ Accepted answer

we ended up solving it on discord.

initial problem was that you op had their parts anchored. make sure you have your parts anchored = false and cancollide false.

the parts needed to be welded and we can't do that in a local script so we put the clothing items in server storage

inside the clothing items we had a script that welded the clothing together. the following script assumes the model has a part named 'attachPart' that is the size and position of the body part you want to attach the clothing to.

local attachPart= script.Parent:WaitForChild("attachPart")
local descendants = script.Parent:GetDescendants() --loop through items children

for i, desc in ipairs(descendants)do
     if desc:IsA("BasePart") or desc:IsA("UnionOperation") then
        desc.Anchored = false --unanchor part
        desc.CanCollide = false

        --weld part to primary part
        local weldConstraint = Instance.new("WeldConstraint")
        weldConstraint.Part0 = attachPart
        weldConstraint.Part1 = desc
        weldConstraint.Parent = attachPart
	model.PrimaryPart = attachPart

    end
end

the model we wanted to attach to the character was a vest, so when the players character loaded, we cloned the vest from the replicated storage and welded it to the player's torso:

game:GetService("Players").PlayerAdded:Connect(function(player)
    player.CharacterAdded:Connect(function(character)
	    --clone vest inside player's torso
	    local vest = game.ServerStorage.Vest:Clone()
	    vest.Parent = character.Torso
	
	    --weld vest to character
	    local weldConstraint = Instance.new("WeldConstraint")
	    weldConstraint.Part0 = character:WaitForChild("Torso")
	    weldConstraint.Part1 = vest.attachPart
	    weldConstraint.Parent = vest.attachPart
	    vest:SetPrimaryPartCFrame(character.Torso.CFrame* CFrame.Angles(0,math.rad(180),0)) 
    end)
end)

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