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

How do I attach Parts to Player's right hand?

Asked by 6 years ago
Edited 6 years ago

I'm trying to make a script weld a Part to the Player's Right hand. I see that the Player's character has a "RightGripAttachment", how would I attach something to that?

0
Create a weld hellmatic 1523 — 6y
0
Yeah I know that.... but how would I weld it to the attachment? MRbraveDragon 374 — 6y

1 answer

Log in to vote
2
Answered by
ax_gold 360 Moderation Voter
6 years ago
Edited 6 years ago

Unfortunately, you can't weld to attachments, but you can weld to other parts. Instead of welding to the RightGripAttachment, just weld it to the RightHand itself. If you need a better explanation, such as how to make welds with a script, let me know in the comments of this answer and I can explain.

Edit:

Alright, since you asked, here's how to make welds with a script:

First, you have to create the Weld with Instance.new(). There are two ways to do this. Either create a Weld or a WeldConstraint. I prefer WeldConstraint, but you can use whichever you want.

Welds and WeldConstraints have 2 properties that are vital to making the weld work. Part0 and Part1. Part0 Should be set to the main part, and Part1 should be set to the other part you want to weld.

The parent of the Weld Should be either the Part0 or Part1 of the Weld.

Here's an example that will weld 2 parts together, the first part being named "Brick0" and the second part being named "Brick1".

local Brick0 = workspace.Brick0
local Brick1 = workspace.Brick1
--Setting the main values

local Weld = Instance.new("WeldConstraint", Brick0) --Creating the Weld
Weld.Part0 = Brick0 --Setting the Part0, the first part in the weld.
Weld.Part1 = Brick1 --Setting the Part1, the second part in the weld.

Now, that's just an example. To attach something to our player's right hand, we'll have to get the character's RightHand with the PlayerAdded() and CharacterAdded() events.

game.Players.PlayerAdded:Connect(function(player)
    player.CharacterAdded:Connect(function(character)
        local RightHand = character:WaitForChild("RightHand")
    end)
end)

Note: When finding player parts with CharacterAdded(), it's best to use WaitForChild() to make sure the part is actually there.

Now that we have the right hand, let's create a part to attach to it.

game.Players.PlayerAdded:Connect(function(player)
    player.CharacterAdded:Connect(function(character)
        local RightHand = character:WaitForChild("RightHand")
        local part = Instance.new("Part", character)
        part.Name = "WeldedBrick"
        part.Size = Vector3.new(1,1,1) 
    end)
end)

Another Note: I put the part in the character and named it "WeldedBrick" so it'd be easy to find. I also changed the size to 1 so it wouldn't be larger than the hand.

Now that the part's in, we need to change it's CFrame to the right hand's CFrame, so they're at the same position and rotation, and can look like they're attached to each other. After that, we create the Weld, and change the Part0 and Part1 to the hand and Part. It doesn't matter which is part0 and which is part1, but I like to make part0 the part and part1 the hand.

game.Players.PlayerAdded:Connect(function(player)
    player.CharacterAdded:Connect(function(character)
        local RightHand = character:WaitForChild("RightHand")
        local part = Instance.new("Part", character)
        part.Name = "WeldedBrick"
        part.Size = Vector3.new(1,1,1) 
        part.CFrame = RightHand.CFrame
        local weld = Instance.new("WeldConstraint", part)
        weld.Part0 = part
        weld.Part1 = RightHand
    end)
end)

And that should do it! If this doesn't work or you have any other quesitons, please let me know,

0
Yes please, that would be appreciated! MRbraveDragon 374 — 6y
0
It took quite a while, but I added in an explanation. I also added in a method to specifically weld something to the righthand. I hope it helps! ax_gold 360 — 6y
0
Thanks for the great explanation! MRbraveDragon 374 — 6y
0
One quick question if you don't mind answering, what are the attachments used for? MRbraveDragon 374 — 6y
View all comments (3 more)
0
attachments are used for things such as accessories. You can also use them to make something like a Ragdoll mode, but I don't know much about that. ax_gold 360 — 6y
0
(A good example of ragdoll mode is in jailbreak, when you fall from too high.) ax_gold 360 — 6y
0
Ahh okay thanks! MRbraveDragon 374 — 6y
Ad

Answer this question