[quote] Look I feel like I let this post drift into the wrong direction.
Here is what Im trying to say.
Lets say I wanted to scale a character by multiplying the size and cframe offsets by 2. Currently when the size of a part changes, the motor is destroyed.
The biggest problem with this is that when the connection between the head and the torso is broken, the Humanoid just dies.
I want to be able to change the size of a part without the connection between Motor6Ds breaking. This behavior should not even apply when using the resize tool, it should just apply to when the size is changed with code. I dont want the C0 or C1 to change at all, when I can just do that myself using some transforming. So the resize tool would still break motors, but code wouldn’t.
Does that make more sense?
[/quote]
Hi there.
[spoiler][code]
– Character resize
local Player = game.Players.LocalPlayer
local Char = Player.Character
local Humanoid = Char.Humanoid
function GetMesh(Obj)
for i,v in pairs(Obj:GetChildren()) do
if v:IsA(“DataModelMesh”) then
return v
end
end
end
function SaveWelds(Obj,Welds,Scale)
if Welds == nil then
local Welds = {}
for i,v in pairs(Obj:GetChildren()) do
if v:IsA(“JointInstance”) then
Welds[#Welds+1] = {v,v.Part0,v.Part1,v.C0,v.C1,v.Parent}
v.Parent = nil
end
SaveWelds(v,Welds,Scale)
end
return Welds
else
for i,v in pairs(Obj:GetChildren()) do
if v:IsA(“JointInstance”) then
Welds[#Welds+1] = {v,v.Part0,v.Part1,v.C0,v.C1,v.Parent}
v.Parent = nil
end
SaveWelds(v,Welds,Scale)
end
end
end
function SaveConnectedParts(Obj,Welds)
if Welds == nil then
local Welds = {}
for i,v in pairs(Obj:GetChildren()) do
if v:IsA(“BasePart”) then
for i2,v2 in pairs(v:GetConnectedParts()) do
Welds[#Welds+1] = {Instance.new(“Weld”),v,v2,v.CFrame:toObjectSpace(v2.CFrame),CFrame.new(0,0,0),v}
end
v:BreakJoints()
end
SaveConnectedParts(v,Welds)
end
return Welds
else
for i,v in pairs(Obj:GetChildren()) do
if v:IsA(“BasePart”) then
for i2,v2 in pairs(v:GetConnectedParts()) do
Welds[#Welds+1] = {Instance.new(“Weld”),v,v2,v.CFrame:toObjectSpace(v2.CFrame),CFrame.new(0,0,0),v}
end
v:BreakJoints()
end
SaveConnectedParts(v,Welds)
end
end
end
function ResizeWelds(Welds,Scale)
for i,v in pairs(Welds) do
v[1].Parent = v[6]
v[1].Part0 = v[2]
v[1].Part1 = v[3]
local Vec = v[4].p
local Vec2 = v[5].p
v[1].C0 = CFrame.new(VecScale)(v[4]-Vec)
v[1].C1 = CFrame.new(Vec2Scale)(v[5]-Vec2)
end
end
function ResizeFunc(Obj,Scale,Welds)
for i,v in pairs(Obj:GetChildren()) do
if v:IsA(“BasePart”) then
local Size = v.Size
for i2,v2 in pairs(v:GetChildren()) do
if v2.Name == “ScaleInserted” then
Size = Sizev2.Scale
v2:Destroy()
elseif v2.Name:sub(1,14) == “ScaleInserted:” then
local X,Y,Z;
for Match in v2.Name:sub(15):gmatch(“[^,%s]+”) do
if Y ~= nil then
Z = tonumber(Match)
elseif X ~= nil then
Y = tonumber(Match)
else
X = tonumber(Match)
end
end
Size = Vector3.new(X,Y,Z)
v2:Destroy()
end
end
v.FormFactor = “Custom”
local CFr = v.CFrame
local Want = SizeScale
v.Size = Want
if v.Size ~= Want then
local Name = “”
for Match in v.Name:gmatch(“[^%s]+”) do
Name = Name…Match
end
local CharMesh = nil
for i,v in pairs(Obj:GetChildren()) do
if v:IsA(“CharacterMesh”) and tostring(v.BodyPart):sub(15) == Name then
CharMesh = v
end
end
if CharMesh == nil then
local Mesh = GetMesh(v)
if Mesh == nil then
local Mesh;
if v:IsA(“WedgePart”) then
Mesh = Instance.new(“SpecialMesh”,v)
Mesh.MeshType = “Wedge”
else
if v.Shape == “Ball” then
Mesh = Instance.new(“SpecialMesh”,v)
Mesh.MeshType = “Sphere”
elseif v.Shape == “Cylinder” then
Mesh = Instance.new(“SpecialMesh”,v)
Mesh.MeshType = “Cylinder”
else
Mesh = Instance.new(“BlockMesh”,v)
end
end
Mesh.Scale = Want/v.Size
Mesh.Name = “ScaleInserted”
else
if (Mesh.ClassName == “SpecialMesh” and Mesh.MeshType ~= Enum.MeshType.FileMesh) or Mesh.ClassName ~= “SpecialMesh” then
Mesh.Scale = Want/v.SizeMesh.Scale
end
end
else
local Mesh = Instance.new(“SpecialMesh”,v)
Mesh.Name = “ScaleInserted:”…tostring(Want)
Mesh.MeshType = “FileMesh”
Mesh.MeshId = “rbxassetid://”…CharMesh.MeshId
–Mesh.TextureId = CharMesh.BaseTextureId – Was too lazy to implement character mesh textures. Sorry.
Mesh.Scale = Vector3.new(1,1,1)Want.X/Scale
end
end
–v.CFrame = CFrame.new(CFr.pScale)(CFr-CFr.p) – Not so good for characters, but for non-jointed objects it’s good.
elseif v:IsA(“DataModelMesh”) then
if v.ClassName == “SpecialMesh” then
if v.MeshType == Enum.MeshType.FileMesh then
v.Scale = v.Scale*Scale
end
end
end
ResizeFunc(v,Scale,Welds)
end
end
function Resize(Obj,Scale)
local Welds = SaveWelds(Obj,nil,Scale)
SaveConnectedParts(Obj,Welds)
ResizeFunc(Obj,Scale,Welds)
ResizeWelds(Welds,Scale)
Humanoid.CameraOffset = Vector3.new(0,Char.HumanoidRootPart.Size.Y/2+Char.Head.Size.Y/2-1.5,0)
Humanoid.WalkSpeed = Humanoid.WalkSpeedScale
Humanoid.MaxHealth = Humanoid.MaxHealthScale
wait(0.25) – i cri cuz the Health script interferes.
Humanoid.Health = Humanoid.Health*Scale – And it still doesn’t always play nicely.
end
Player.Chatted:connect(function(m)
if m:sub(1,3) == ";s " then
local Scale = tonumber(m:sub(4))
if Scale then
if (Char.Head.Size*Scale).Z < 0.4 then – Animations act all wonky when you get pretty small.
Char.Animate.Disabled = true – Unfortunately, any animations that were playing when you did this will keep playing.
– A hacky fix for this is to remove the old humanoid and put a new one in, but then the character won’t respawn when they die.
else
Char.Animate.Disabled = false
end
Resize(Char,Scale)
end
end
end)
[/code][/spoiler]