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

How do i temporarily weld part to a player?

Asked by 6 years ago

Im trying to do this to learn how to make hitboxes but i dont know how could someone explain welding to me and how to do it?

0
welds are not for hitboxes, welds hold parts relative to each other GoldAngelInDisguise 297 — 6y
0
,So what, help the guy anyway, would you rather receive that comment or an answer that fixes your issues? Ziffixture 6913 — 6y
0
Well he is right. I prefer the former over the latter tbh. User#24403 69 — 6y

1 answer

Log in to vote
2
Answered by
Ziffixture 6913 Moderation Voter Community Moderator
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:

1--// the torso, and sword
2local Player = game:GetService("Players").LocalPlayer
3local Character = player.Character
4local Torso = Character:FindFirstChild("Torso")
5local Sword = workspace:WaitForChild("Sword")

Next, we need to create the weld instance

1local 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:

1--// Before working with the Objects though, we need to make sure the Object that's going to attach to the other isn't anchored. Next, since we're giving it an angle, and a position on the back; CFrame, we have to set this first.
2 
3if (Sword and Character) then --// Extra precautionary measure
4    Sword.Anchored = false
5    Sword.CFrame = Torso.CFrame * CFrame.new(0,0,1) * CFrame.Angles(0,0,45)
6end

Now we set the weld:

1if (Sword and Character) then --// Extra precautionary measure
2    Sword.Anchored = false
3    Sword.CFrame = Torso.CFrame * CFrame.new(0,0,1) * CFrame.Angles(0,0,45)
4    Weld.Part0 = Torso --// Part0 is the Object the other Object is welding to
5    Weld.C0 = Torso.CFrame:inverse() --// Makes this object follow the CFrame of the Object it's going to weld with, this is very important
6    Weld.Part1 = Sword --//Object thats going to attach to the other
7    Weld.C1 = Sword.CFrame:inverse() --//Now that their CFrames are binded, they're seem as if it's completely following, or in other terms mimicking.
8end

Attach everything

01local Player = game:GetService("Players").LocalPlayer
02local Character = player.Character
03local Torso = Character:FindFirstChild("Torso")
04local Sword = workspace:WaitForChild("Sword")
05local Weld = Instance.new("Weld")
06if (Sword and Character) then
07    Sword.Anchored = false
08    Sword.CFrame = Torso.CFrame * CFrame.new(0,0,1) * CFrame.Angles(0,0,45)
09    Weld.Part0 = Torso
10    Weld.C0 = Torso.CFrame:inverse()
11    Weld.Part1 = Sword
12    Weld.C1 = Sword.CFrame:inverse()
13end

Hope this helps

0
Remember if this helps, click the 'accept answer' button, help me help you:) Ziffixture 6913 — 6y
0
where can i learn more about welding and humaoid model parts? EzireBlueFlame 14 — 6y
0
You can learn more about advanced joint-welding here: https://developer.roblox.com/articles/Weld Ziffixture 6913 — 6y
Ad

Answer this question