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