I'm working on a morphing system, but it doesn't seem to be instant, like, has a delay when welding. Does anyone have any tips and recommendations on how can I optimize scripts that usually weld stuff together? Doesn't matter if it's normal welds or Motor6D.

Example module script that I made and use:

game:GetService("RunService").Heartbeat:Wait()

local Morphs = game.ServerStorage:FindFirstChild("Characters")


local MorphModule = {}

function MorphModule.Morph(player,MorphName,Stats)

if Morphs:FindFirstChild(MorphName) and player.Character.Humanoid.Health ~= 0 then
local humanoid = player.Character:FindFirstChild("Humanoid")

local morph = Morphs:FindFirstChild(MorphName)
local morph_model = morph.Rig
local morph_extras = morph.Extras

local tag = Instance.new("BoolValue",player.Character)
tag.Value = true
tag.Name = "Morphed"

humanoid.WalkSpeed = Stats["WalkSpeed"]	
humanoid.JumpPower = Stats["JumpPower"]	
humanoid.HipHeight = Stats["HipHeight"]	
humanoid.MaxHealth = Stats["MaxHealth"]
humanoid.Health = Stats["MaxHealth"]
player.Character.Torso:FindFirstChild("NameGui").ExtentsOffset = Vector3.new(0,Stats["NameOffset"],0)	

for a,b in pairs(player.Character:GetDescendants()) do
if b.ClassName == "MeshPart" or b.ClassName == "Part" or b.ClassName == "UnionOperation" or b.ClassName == "Decal" then
b.Transparency = 1	
end			
if b.Name == "Animate" then
b.Disabled = true
end
end		

local rig_clone = morph_model:Clone()

--Weld
rig_clone:FindFirstChild("HumanoidRootPart").CFrame = player.Character.HumanoidRootPart.CFrame
	local WeldEnt = Instance.new("Weld",rig_clone:FindFirstChild("HumanoidRootPart"))
	WeldEnt.Part0 = rig_clone:FindFirstChild("HumanoidRootPart")
	WeldEnt.Part1 = player.Character.HumanoidRootPart
	local CJ = CFrame.new(rig_clone:FindFirstChild("HumanoidRootPart").Position)
	local C0 = rig_clone:FindFirstChild("HumanoidRootPart").CFrame:inverse()*CJ
	local C1 = player.Character.HumanoidRootPart.CFrame:inverse()*CJ
	WeldEnt.C0 = C0
	WeldEnt.C1 = C1 

--Uncollide and unanchor.
for a,b in pairs(rig_clone:GetChildren()) do
b.Parent = player.Character
if b.ClassName == "MeshPart" or b.ClassName == "Part" or b.ClassName == "UnionOperation" then
b.CanCollide = false
b.Anchored = false	
end
end

for a,b in pairs(morph_extras:GetChildren()) do
for d,c in pairs(b:GetChildren()) do
	
if not b.Name == "CharacterScripts" or b.Name == "Backpack" or b.Name == "PlayerGui" then
c:Clone().Parent = player[b.Name]	
				else
c:Clone().Parent = player.Character
end

end	
end
																																
	elseif not Morphs:FindFirstChild(MorphName) then
warn("Morphing Error: " .. MorphName .. " was not found in " .. Morphs.Name .. " folder, check if the name of the morph is correct.")		
return
	elseif player.Character.Humanoid.Health == 0 then
warn("Morphing Error: " .. player.Name .. " is Dead.")		
return
end

end

return MorphModule

2 comments

0

If we can't have a example of your code, we won't be able to help you properly.

0

I added the code.