hi, ive been suffering greatly for 5 hours.
I am trying to create a function that can be used to scale character models using a given scale factor. (For example, 0.5 to half its size or 2 to double its size). The models are entirely custom creatures containing humanoids–not roblox R6/R15 models–which contain Motor6Ds and WeldConstraints. I’ve been trying for hours to figure this out with various functions but keep encountering different issues.
Presently I’ve arrived at this code, which works for all models when put into the console when not playing the game, but when used on the player’s character in-game it works only for some models and not others and I have no idea why. For the models for which it doesn’t work, parts which have their position directly set (rather than being altered as the C0/C1 of a joint) are all displaced vertically by the same unknown distance.
local function scaleModel(model, scaleFactor)
local dilationCentre = model.PrimaryPart.Position
local WeldConstraints = {}
for _, d in pairs(model:GetDescendants()) do
if d:IsA("JointInstance") then
d.Part0:SetAttribute("Jointed", true)
d.Part1:SetAttribute("Jointed", true)
elseif d:IsA("WeldConstraint") then
WeldConstraints[d] = {d.Part0, d.Part1}
d.Part0 = nil d.Part1 = nil
end
end
for _, d in pairs(model:GetDescendants()) do
if d:IsA("BasePart") then
d.Size = d.Size * scaleFactor
if not d:GetAttribute("Jointed") then
d.Position = ((d.Position - dilationCentre) * scaleFactor) + dilationCentre
end
elseif d:IsA("JointInstance") then
d.C0 = d.C0 + d.C0.Position*(scaleFactor - 1)
d.C1 = d.C1 + d.C1.Position*(scaleFactor - 1)
end
end
-- Restore WeldConstraints
for WeldConstraint, Attachments in pairs(WeldConstraints) do
WeldConstraint.Part0 = Attachments[1]
WeldConstraint.Part1 = Attachments[2]
end
end
I’ve been scouring the forums for hours to no avail. Can anyone help me fix this function, or recommend a public module or plugin that would allow me to resize complex character models during runtime?