I’m trying to weld the sword to the sheath in the script but I’m having trouble finding a method to do it. I’m kind of new to welding and Setting the Primary Part.
I am trying to weld the sword like that but on the character.
game.Players.PlayerAdded:Connect(function(player)
player.CharacterAdded:Connect(function(Character)
local swordCFrame = CFrame.new(-408.728, 1.765, -27.354)
local char = player.Character
local HumanoidRootPart = char:FindFirstChild("HumanoidRootPart")
local weld = Instance.new("Weld", HumanoidRootPart)
local humanoid = char:FindFirstChildOfClass("Humanoid")
local RS = game.ReplicatedStorage
local SwordCase = RS.SwordWeldPart:Clone()
weld.Part0 = HumanoidRootPart
SwordCase.Parent = HumanoidRootPart
weld.Part1 = SwordCase
SwordCase.Anchored = false
local Sword = RS.Sword:Clone()
Sword:PivotTo(SwordCase.CFrame)
Sword.Parent = Character
local Weld2 = Instance.new("Weld")
Weld2.Part0 = Sword.PrimaryPart
SwordCase.Parent = SwordCase
Weld2.Part1 = SwordCase
end)
end)
Don’t use Sword:PivotTo()
after it has been welded. You need to set the C0
and C1
properties of the weld. They’re in object space, so set it to CFrame.Angles(math.pi/2,0,0)
or something like that.
1 Like
So if I’m correct I need to get the CFrame position of the sword and then set the weld0 and Weld 1 to the CFrame? I kind of new to using CFrame.Angles and Math.pi. Do I have to divide something Inside of the equation?
No, you use Weld.C0
. It has its own property for this.
No, you can use math.rad
to convert degrees into radians. Think of it like setting a part’s orientation.
Did i do it right?
game.Players.PlayerAdded:Connect(function(player)
player.CharacterAdded:Connect(function(Character)
local swordCFrame = CFrame.new(-408.728, 1.765, -27.354)
local char = player.Character
local HumanoidRootPart = char:FindFirstChild("HumanoidRootPart")
local weld = Instance.new("Weld", HumanoidRootPart)
local humanoid = char:FindFirstChildOfClass("Humanoid")
local RS = game.ReplicatedStorage
local SwordCase = RS.SwordWeldPart:Clone()
weld.Part0 = HumanoidRootPart
SwordCase.Parent = HumanoidRootPart
weld.Part1 = SwordCase
SwordCase.Anchored = false
local Sword = RS.Sword:Clone()
Sword.Parent = Character
local Weld2 = Instance.new("Weld")
Weld2.Part0 = CFrame.Angles(math.rad(-391.837), math.rad(1.079), math.rad(-1.92))
SwordCase.Parent = SwordCase
Weld2.Part1 =CFrame.Angles(math.rad(-391.837), math.rad(1.079), math.rad(-1.92))
end)
end)
Wait I got an error /: it says object expected, got a CFrame. so Do i not put CFrame there??
No. It’s not part0
or part1
. The property is called C0
so set Weld2.C0 = CFrame.Angles(math.rad(90), math.rad(90), math.rad(0))
.
Do I put in exactly 90, 90, and 0 for the radians? or do I use the exact CFrames for the sword position?
Also I’m getting an error for the part0 weld… I welded it to the sword… Can I weld a model or no?
Part0
and Part1
need to be parts, like wedges, unions, and mesh parts. They can’t be a model.
my sword is already like welded, so how am I gonna weld it inside of the case then? Is there a way I can do that?
You set weld2.Part0
to the sword’s handle and weld2.Part1
to the SwordCase
So I didnt get an error but the sword and the sword case aren’t showing on my character. Which part did I mess up?
local Sword = RS.Sword:Clone()
Sword.Parent = Character
local Weld2 = Instance.new("Weld")
Weld2.Part0 = Sword.Handle
Sword.Parent = Character
Weld2.Part1 = SwordCase
weld.C0 = CFrame.Angles(math.rad(90),math.rad(90),math.rad(0))
end)
end)
Actually, I think I was wrong here. You need to weld the part0 to the handle and the part1 to the character’s right arm.
are you sure because I want it to be inside of the case on the side of my character when I spawn
Yes. This time, I’m sure. Unless the sword comes out of its case.
Im planning on scripting it so when I equip it the weld will break and it’ll come out of the case like on Zo or Dynasty and when I reequip it the weld we be back where it was
Heres what Im trying to refrence but some of the CFrames a outdated or something