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

How do I attach objects to a player model?

Asked by 4 years ago

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)

0
When you used the weldconstraint, were the models you were trying to attach anchored or not? CeramicTile 847 — 4y

1 answer

Log in to vote
0
Answered by
royaltoe 5144 Moderation Voter Community Moderator
4 years ago

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)
Ad

Answer this question