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?
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,