Weldconstraint rotation issue

i have the next modular script in hand

local ReplicatedStorage = game:GetService("ReplicatedStorage")
local Morphs = ReplicatedStorage:WaitForChild("Morphs")

local m = {}
m.__index = m

function m.new()
	local self = setmetatable({}, m)
	
	return self
end

function m:AttachByTeam(character : Model, team : string)
	for _,v : Model? in pairs(Morphs:WaitForChild(team):GetChildren()) do
		local item = v:Clone()
		item.Parent = character
		
		item.PrimaryPart.CFrame = character:WaitForChild(v.Name).CFrame * CFrame.new(character:WaitForChild(v.Name).Size.X/2,0,0) * CFrame.Angles(0, math.rad(90), 0)
		
		local weld = Instance.new("Weld")
		weld.Part0 = character:WaitForChild(v.Name)
		weld.Part1 = item.PrimaryPart
		
		weld.Parent = item
	end
end


return m

and this is where its called

local ReplicatedStorage = game:GetService("ReplicatedStorage")
local Modules = ReplicatedStorage:WaitForChild("Modules")

local morphs = require(Modules:WaitForChild("Morphs"))
local Morph = morphs.new()

game:GetService("Players").PlayerAdded:Connect(function(player: Player)
	player.CharacterAdded:Connect(function(character)
		Morph:AttachByTeam(character, player.Team.Name)
	end)
end)

in morphs folder, i have the next as an example
изображение

the point is to attach the items to specific bodyparts, but the rotation doesnt work as intended:
изображение

i would really appreciate if anyone finds the solution

1 Like

If the problem is that ataches with a wrong orientation maby you can add 90 grades to the item rotation before attaching it.

1 Like

i tried but unfortunately no results

try changing it by this

item.PrimaryPart.CFrame = character:WaitForChild(v.Name).CFrame * CFrame.new(character:WaitForChild(v.Name).Size.X/2,0,0) * CFrame.Angles(0, math.rad(90), 0)

math.rad(90) Change this value to check if it afects to the rotaion.

i tried without the angles, and the other time without the 2nd cframe i make, nope, it doesnt affect rotation at all

Try using WeldConstraint instead of Weld

local weld = Instance.new("WeldConstraint")

I think Weld changes Part1 CFrame to Part0 CFrame automatically.

no, nothing changes when i use weldconstraint

I don’t know what it is happening, WeldConstraint should have worked correctly.

for people who will get stuck in the same problem, ive considered the next stuff - i used motor6ds and copied character libs as the primary, parts, so in the end my code and morph looks like this:

function m:AttachByTeam(character : Model, team : string)
	for _,v in pairs(Morphs:WaitForChild(team):GetChildren()) do
		
		local item = v:Clone()
		local weld = Instance.new("Motor6D")
		
		item.Parent = character
		item.PrimaryPart.CFrame = character:WaitForChild(v.Name).CFrame * CFrame.Angles(0,0,0)
		
		weld.Part0 = character:WaitForChild(v.Name)
		weld.Part1 = item.PrimaryPart
		
		weld.C0 = character:WaitForChild(v.Name).CFrame:Inverse()
		weld.C1 = item.PrimaryPart.CFrame:Inverse()
		
		weld.Parent = item
		
	end
end

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