How to attach a model to a player with correct orientation

Hello,

Below is a clip of a key activated script in which a model is cloned and positioned to the characters CFrame. I would like to make it to where the model is floating above the character a little behind its head.

https://gyazo.com/9bb25cc93ac9cc409a7c6ba68a17799a

I have tried working with attachments and welding along with CFrame and Position and havent been able to figure it out on my own. Help would be appreciated.

The goal is to keep the model floating above the characters head and will follow when the player turns.

make a weld constraint and do something like:

local partToClone = pathToPart:Clone() -- wherever that part is
local player = whoeverYouWantItAbove -- the player to which it'll weld
local character = player.Character
local humRootPart = character.HumanoidRootPart
local weldCons = Instance.new("WeldConstraint")

weldCons.Parent = partToClone
weldCons.Part0 = partToClone
partToClome.CFrame = humRootPart.CFrame * CFrame.new(0, 5, 0) -- this will make it 5 studs above the players root part
partToClone.Parent = workspace
partToClone.Part1 = humRootPart
1 Like

Very helpful, what about in terms of the orientation. Whenever I rotate it through code it messes up the whole models look.

You have to rotate the primary part, if it’s all properly welded it should turn just fine

1 Like

I have tried changing the orientation of the primary part through the model itself and alone with the part but it will not change direction.

Hmm, bit confused, could you please send a video?

The rotation is test numbers to see how it rotates but even with (0,0,0) its in the same position as before I updated the primary part with the new orientation.

https://gyazo.com/fe4c4fce472601bd17c8fde1c9b10d0f
This is the product of both no change and change in the primary parts orientation, without code, only through properties.

N1 is your primary part so try changing the orientation of that, not your model

note: pivot changes the pivot point of the model (what it moves around) and not the model

perhaps weld all the parts in the model, and change the CFrame of the primary part to the CFrame of your character, and multiply the cframe so the model floats above your head.

I did do that aswell as referenced here, no change unfortunately

I appreciate the response, we have figured that issue out, the new problem is trying to orient it the correct way.

have you done it through a script?

If you mean changing the primary parts orientation through code, I have through model.primarypart but not through the part alone.

–Edit: To which it messed up the model.

could you please send a video of it messing up the model? Also have you done something like:

partToClone.CFrame = humRootPart.CFrame * CFrame.new(0, 5, 0)
partToClone.CFrame = partToClone.CFrame * CFrame.fromEulerAnglesXYZ(90, 90, 0)

For sure, and I have not tried your way yet. I will after sending you as you requested.

I apologize for audio, the orientation code is marked with highlight.

https://gyazo.com/12e4c676463a0ae9b39e5c0a7a8aff7c

After replacing that line of code with yours I have gotten it to orient without messing up the model.

Thank you for your help. I would like to know why orientation alone doesnt work VS. CFrame?

basically CFrame is orientation plus position, not sure why orientation isn’t working for you but I usually just stick to CFrame whenever I’m doing position or rotation relating to anything connected to another part. Now that I think about it I think the 90 is in radians a not degrees so that could be it. You would have to do something like :

partToClone.Orientation += Vector3.new(90, 90, 0)

not sure if this would work as I don’t use it much and I’m writing this from my phone, please lmk.

1 Like