0

CFrame: How to weld objects to player in a certain direction?

I have a model which needs to be welded to the player's left arm, and I want it to face the front of it.

This was the old script, but it only worked if the player doesn't move after spawning. If the player turns before the object is welded, the object will not be placed facing the front of the arm.

wait()
local char = plr.Character
local c = game.ServerStorage["Object Name"]:Clone()
local weld = Instance.new("WeldConstraint")
local armPos = char["Left Arm"].Position
weld.Parent = c.Base
weld.Part0 = c.Base
weld.Part1 = char["Left Arm"]
c.Parent = char


I want it to always face the front, even if the player is laying down. I tried doing this, but it still works the same.

local char = plr.Character
local c = game.ServerStorage["Object Name"]:Clone()
local weld = Instance.new("WeldConstraint")
local armPos = char["Left Arm"].Position
weld.Parent = c.Base
weld.Part0 = c.Base
c.Base.CFrame = CFrame.new(armPos,Vector3.new(armPos.x,armPos.y,armPos.z-1))
weld.Part1 = char["Left Arm"]
c.Parent = char


I'm not good with CFrames, sorry if this is something easy but I have no idea of what to do. Thank you in advance.

0
I'd take a look at using the characters attachments instead of setting a CFrame for the model. ForeverBrown 355 — 1y
0
What you would use if you threw it into an accessory: https://developer.roblox.com/en-us/api-reference/function/Humanoid/AddAccessory ForeverBrown 355 — 1y
0
lucyy's answer seem like it would work, are you sure that the "front" of it is the actual face you want. and you should be using :SetPrimaryPartCFrame() instead. and do you want the front of the model to touch the front of the arm instead? GGRBXLuaGG 417 — 1y

0
opgeeza 1310
1 year ago

I suggest you try work with CFrame.Angles(),

but to make it easier, use math.rad(). Like so:

local Player = game.Players.LocalPlayer
local Character = Player.Character or Player.CharacterAdded:Wait()

local Part = Instance.new('Part', workspace)
Part.CanCollide = false
Part.Anchored = false

local Weld = Instance.new('Weld', Part)
Weld.Part0 = Part
Weld.Part1 = Character:WaitForChild('Left Arm')
Weld.C0 = CFrame.new(0,0,0) * CFrame.Angles(math,rad(0), math.rad(0), math.rad(0)) -- it will stay where the arm CFrame is, but you can rotate it using math.rad().

0
c.Parent = char