I tried to weld the sword case to the characters side but It didn’t work. How exactly do I script this?
game.Players.PlayerAdded:Connect(function(player)
player.CharacterAdded:Connect(function(Character)
local case = script.Case:Clone()
case:PivotTo(Character.CFrame)
case.Parent = Character
local Weld = Instance.new("WeldConstraint")
Weld.Part0 = case
Weld.Part1 = Character.HumanoidRootPart
Weld.C0 = Weld.Part0.CFrame:ToObjectSpace(Weld.Part1.CFrame)
Weld.Parent = Character
end)
end)
Weld.Part0 = Character.HumanoidRootPart
Weld.Part1 = case
It may even work better in your favor as well, if you instead change the CFrame of the case to face the direction the Character’s HumanoidRootPart is facing. Something like this
local HumanoidRootPart = Character.HumanoidRootPart
local hrpOrigin = HumanoidRootPart.CFrame
local calculatedCFrame = CFrame.new(hrpOrigin + Vector3.new(-HumanoidRootPart.Size.X, HumanoidRootPart.Size.Y, 0))
-- if it's a model, set the primary part to the case's base.
case:SetPrimaryPartCFrame(calculatedCFrame))
-- else, use this.
case.CFrame = calculatedCFrame
local Weld = Instance.new("WeldConstraint")
-- you don't have to change the C0. matter of fact, I don't think it's even an existing property for WeldConstraint.
Weld.Part0 = Character.HumanoidRootPart
Weld.Part1 = case
Weld.Parent = case
game.Players.PlayerAdded:Connect(function(player)
player.CharacterAdded:Connect(function(Character)
local case = script.Case:Clone()
case:PivotTo(Character.CFrame)
case.Parent = Character
local Weld = Instance.new("WeldConstraint")
Weld.Part0 = Character.HumanoidRootPart
Weld.Part1 = case
Weld.Parent = case
end)
end)
local HumanoidRootPart = Character.HumanoidRootPart
local hrpOrigin = HumanoidRootPart.CFrame
local calculatedCFrame = CFrame.new(hrpOrigin + Vector3.new(-HumanoidRootPart.Size.X, HumanoidRootPart.Size.Y, 0))
-- if it's a model, set the primary part to the case's base.
case:SetPrimaryPartCFrame(calculatedCFrame))
local Weld = Instance.new("WeldConstraint")
-- you don't have to change the C0. matter of fact, I don't think it's even an existing property for WeldConstraint.
Weld.Part0 = Character.HumanoidRootPart
Weld.Part1 = case
Weld.Parent = case
And like I said, you should make the base of the sheath the primary part of the model. If you don’t know how to do that, select the model, click on primary part, then find the part that you want to be the primary part.
You can use accessories. Put your case in the accessory and call it Handle, make an attachment inside the Handle and name it based on what attachment you want it to stick to on someone’s character, and then use the move tool (not the attachment’s move tool it’s quite broken)!
Also, to get a dummy to edit on, look up in the toolbox, “Attachment dummy your rig type.”
Edit: welding and motor6Ds are NOT the way to go at all.
However, i mean accessories are a more hacky way, but i dont recommend them because sometimes they can be stuck to the center of the hrp (humanoidrootpart)