Answered by
6 years ago Edited 6 years ago
Think of welding as anchoring a part, except instead of it floating there not moving, it stays attached to whatever it was told to stick to, even move around with it if you'd like
Judging by the fact you'd like to weld to a character this is what it would look like, and for the example, we'll do an angled sword attached to the back.
The first step is to index the Objects you're working with, for this transaction, we're looking for:
2 | local Player = game:GetService( "Players" ).LocalPlayer |
3 | local Character = player.Character |
4 | local Torso = Character:FindFirstChild( "Torso" ) |
5 | local Sword = workspace:WaitForChild( "Sword" ) |
Next, we need to create the weld
instance
1 | local Weld = Instance.new( "Weld" ) |
After that, we need to start using this weld
to bind both objects together. This is what the process looks like:
3 | if (Sword and Character) then |
5 | Sword.CFrame = Torso.CFrame * CFrame.new( 0 , 0 , 1 ) * CFrame.Angles( 0 , 0 , 45 ) |
Now we set the weld:
1 | if (Sword and Character) then |
3 | Sword.CFrame = Torso.CFrame * CFrame.new( 0 , 0 , 1 ) * CFrame.Angles( 0 , 0 , 45 ) |
5 | Weld.C 0 = Torso.CFrame:inverse() |
7 | Weld.C 1 = Sword.CFrame:inverse() |
Attach everything
01 | local Player = game:GetService( "Players" ).LocalPlayer |
02 | local Character = player.Character |
03 | local Torso = Character:FindFirstChild( "Torso" ) |
04 | local Sword = workspace:WaitForChild( "Sword" ) |
05 | local Weld = Instance.new( "Weld" ) |
06 | if (Sword and Character) then |
07 | Sword.Anchored = false |
08 | Sword.CFrame = Torso.CFrame * CFrame.new( 0 , 0 , 1 ) * CFrame.Angles( 0 , 0 , 45 ) |
10 | Weld.C 0 = Torso.CFrame:inverse() |
12 | Weld.C 1 = Sword.CFrame:inverse() |
Hope this helps