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

How to properly weld a part to a player's torso?

Asked by
rexhawk 222 Moderation Voter
5 years ago

I'm working on handcuffs, and I'm trying to make a part that welds on the officer and the suspect to bind them together, from there I could disable the suspect's controls to let the officer have full control. The problem is that whenever I try to weld a part to the officer, if glitches and the part end up welded to my torso, but it's in a very different spot then where it was intended.

What I'm trying to do: https://i.vgy.me/MKhmDv.png What it's doing: https://i.vgy.me/ydtYPZ.png

Any help would greatly be appreciated!

Code that creates the part and adds the weld:

local attach = Instance.new("Part")
attach.Parent = game.Workspace
attach.Size = Vector3.new(1,2,3)
attach.CFrame = officerChar.HumanoidRootPart.CFrame * CFrame.new(0.5,0,-1)
local weld1 = Instance.new("Weld")
weld1.Parent = officerChar
weld1.Part0 = officerChar.HumanoidRootPart
weld1.Part1 = attach
weld1.C0 = officerChar.HumanoidRootPart.CFrame:inverse()
weld1.C1 = attach.CFrame:inverse()

2 answers

Log in to vote
0
Answered by 5 years ago

line 4 change

attach.CFrame = officerChar.HumanoidRootPart.CFrame * CFrame.new(0.5,0,-1)

to

attach.CFrame = CFrame.new(officerChar.UpperTorso.Position)-- this changes the location to the uppertorso, looks like that place on the pic

but there u got how to change the cframe of a part, u dont change the cframe to another cframe, u change it to another position cframe means practicly "place to put it"

Ad
Log in to vote
0
Answered by 5 years ago
Edited 5 years ago

I generally would just set the offsets to the welds CO/C1 instead of relying on inverse.

I am not able to replicate your error in a blank project.

You should also be parenting a new instance last as you should first setup the instance then connect any events before making it part of the game. This also saves on network replication. ``` local attach = Instance.new("Part") attach.Size = Vector3.new(1,2,3)

local weld1 = Instance.new("Weld") weld1.Part0 = officerChar.HumanoidRootPart weld1.Part1 = attach weld1.C0 = CFrame.new(0.5, 0, -1) weld1.C1 = CFrame.new()

-- parent last weld1.Parent = officerChar attach.Parent = game.Workspace ```

Hope this helps.

Answer this question