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
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