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:

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

Next, we need to create the weld instance

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:

--// 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.

if (Sword and Character) then --// Extra precautionary measure
    Sword.Anchored = false
    Sword.CFrame = Torso.CFrame * CFrame.new(0,0,1) * CFrame.Angles(0,0,45)
end

Now we set the weld:

if (Sword and Character) then --// Extra precautionary measure
    Sword.Anchored = false
    Sword.CFrame = Torso.CFrame * CFrame.new(0,0,1) * CFrame.Angles(0,0,45)
    Weld.Part0 = Torso --// Part0 is the Object the other Object is welding to
    Weld.C0 = Torso.CFrame:inverse() --// Makes this object follow the CFrame of the Object it's going to weld with, this is very important
    Weld.Part1 = Sword --//Object thats going to attach to the other
    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.
end

Attach everything

local Player = game:GetService("Players").LocalPlayer
local Character = player.Character
local Torso = Character:FindFirstChild("Torso")
local Sword = workspace:WaitForChild("Sword")
local Weld = Instance.new("Weld")
if (Sword and Character) then
    Sword.Anchored = false
    Sword.CFrame = Torso.CFrame * CFrame.new(0,0,1) * CFrame.Angles(0,0,45)
    Weld.Part0 = Torso 
    Weld.C0 = Torso.CFrame:inverse()
    Weld.Part1 = Sword
    Weld.C1 = Sword.CFrame:inverse()
end

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