How do I script a model's orientation properly?

In my game, multiple swords are going to be available. I’ve set up a system (using the first sword added) that welds the sword to the players right hand and orients it correctly, I would like all of the other sword models to also be oriented correctly in the players hand.

My problem is that upon adding the second sword to the game, even though the orientation of the model and all parts in the model match the first sword, it’s orientation is different in-game (its broadsided).

Screen shots below:

First Sword Added (correct orientation):

Second Sword Added (incorrect orientation, it is broadsided)

Models Properties:

First Sword Added (correct orientation):

Second Sword Added (incorrect orientation, it is broadsided)

Here’s the Chunk of Script that Orients the Sword:

sword:WaitForChild("Blade").CFrame = char.RightHand.CFrame*CFrame.Angles(math.rad(180),math.rad(90),math.rad(90))*,3.765,0))

	local weld ="WeldConstraint")
	weld.Part0 = char.RightHand
	weld.Part1 = sword.Blade
	weld.Parent = char.RightHand
	sword.Parent = char

Help is appreciated, I’ve tried researching on the forum but to no avail (I may just not know the correct name for my problem).

If any further details are needed please ask!


I’m just posting this reply to bump this post since I’m getting no responses

This is just due to the meshes used in the 2nd sword being in a different rotation before they were exported

Gonna reimport it and give it a shot, thanks.

You could try using “:GetPivot()” and “:PivotTo()” and get the pivot of first sword and pivot the second sword to that cframe.

Or you add a invisible “PrimaryPart” inside the swords with the same orientation.

Honestly an easier method to go about a changed orientation between multiple meshes, instead of re-exporting it to get it to align, you could mark an “Orientation” Attribute then have your weld depend on that offset orientation value.

Such that:

local position_offset = sword:GetAttribute("Offset") or
local orientation_offset = sword:GetAttribute("Orientation") or
local x, y, z = math.rad(orientation_offset.X), math.rad(orientation_offset.Y), math.rad(orientation_offset.Z)

weld.C1 = * CFrame.Angles(x, y, z)

This way allows you to have different attachment points for different sized items along with different/unique orientation methods without the need of re-exporting an already good model.

1 Like

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.