I need to update the system of "fusion" with players

And so I’m making a system with player merges, and I have results, but I would like to make it possible to merge into 3 or more people rather than just 2. This is what my system represents and its code.

– The code of this system

local Players = game:GetService("Players")
local ReplicatedStorage = game:GetService("ReplicatedStorage")
local TweenService = game:GetService("TweenService")

local MainCameraEvent = ReplicatedStorage.Remotes.MainCamera
local MainGuiEvent = ReplicatedStorage.Remotes.MainGui

local FusionModule = {}
FusionModule.AlreadyFusioning = {}

function glowModel(model: Model)
	if model and not model:FindFirstChildWhichIsA("Highlight") then
		local highlight = Instance.new("Highlight")
		highlight.FillTransparency = 1
		highlight.FillColor = Color3.fromRGB(255, 255, 255)
		highlight.OutlineTransparency = 1
		highlight.Adornee = model
		highlight.Parent = model
		
		local tweenFillTransparency = TweenService:Create(highlight, TweenInfo.new(0.5, Enum.EasingStyle.Sine, Enum.EasingDirection.InOut), {
			FillTransparency = 0
		})
		
		tweenFillTransparency:Play()
		tweenFillTransparency.Completed:Once(function()
			tweenFillTransparency:Destroy()
		end)
	end
end

function unglowModel(model: Model)
	if model and model:FindFirstChildWhichIsA("Highlight") then
		local highlight = model:FindFirstChildWhichIsA("Highlight")

		local tweenFillTransparency = TweenService:Create(highlight, TweenInfo.new(0.5, Enum.EasingStyle.Sine, Enum.EasingDirection.InOut), {
			FillTransparency = 1
		})

		tweenFillTransparency:Play()
		tweenFillTransparency.Completed:Once(function()
			tweenFillTransparency:Destroy()
			model:FindFirstChildWhichIsA("Highlight"):Destroy()
		end)
	end
end

function tweenToPos(instance: Model, cframe)
	local cfValue = Instance.new("CFrameValue")
	cfValue.Value = instance.HumanoidRootPart.CFrame
	
	cfValue:GetPropertyChangedSignal("Value"):Connect(function()
		instance.HumanoidRootPart:PivotTo(cfValue.Value)
	end)
	
	local tween = TweenService:Create(cfValue, TweenInfo.new(0.5, Enum.EasingStyle.Quad, Enum.EasingDirection.Out), {
		Value = cframe
	})

	tween:Play()
	tween.Completed:Once(function()
		tween:Destroy()
		cfValue:Destroy()
	end)
end

function hideModel(model:Model)
	for _, part in pairs(model:GetDescendants()) do
		if part:IsA("BasePart") or part:IsA("Part") or part:IsA("Decal") and part.Name ~= "HumanoidRootPart" then
			part.Transparency = 1
		end
	end
end

function showModel(model:Model)
	for _, part in pairs(model:GetDescendants()) do
		if part:IsA("BasePart") or part:IsA("Part") or part:IsA("Decal") then
			part.Transparency = 0
			
			if part.Name == "HumanoidRootPart" then
				part.Transparency = 1
			end
		end
	end
end

function FusionModule:CreateAccessorysFusion(c1: Model, c2: Model, controllModel: Model)
	if c1 and c2 then
		for _, accesory in pairs(c1:GetChildren()) do
			if accesory:IsA("Accessory") then
				local accesoryClone = accesory:Clone()
				accesoryClone.Parent = controllModel
				accesoryClone.Handle.Transparency = 0
				accesoryClone:AddTag(c1.Name)
			end
		end
		
		for _, accesory in pairs(c2:GetChildren()) do
			if accesory:IsA("Accessory") then
				local accesoryClone = accesory:Clone()
				accesoryClone.Parent = controllModel
				accesoryClone.Handle.Transparency = 0
				accesoryClone:AddTag(c2.Name)
			end
		end
		
		local faceRandom = math.random(1, 2)
		controllModel.Head.face.Transparency = 1
		
		if faceRandom == 1 then
			local facec: Decal = c1.Head.face:Clone()
			facec.Transparency = 0
			facec.Parent = controllModel.Head
		else
			local facec: Decal = c1.Head.face:Clone()
			facec.Transparency = 0
			facec.Parent = controllModel.Head
		end
		
		local shirtRandom = math.random(1, 4)
		
		if shirtRandom == 1 then
			c1.Shirt:Clone().Parent = controllModel
		else
			c2.Shirt:Clone().Parent = controllModel
		end
		
		local pantsRandom = math.random(1, 4)

		if pantsRandom == 1 then
			c1.Pants:Clone().Parent = controllModel
		else
			c2.Pants:Clone().Parent = controllModel
		end
	end
end

function FusionModule:GiveControl(modelControll: Model, controllCharacter: Model)
	local toTeleportCF = modelControll.HumanoidRootPart.CFrame
	
	for _, part in pairs(controllCharacter:GetChildren()) do
		if part:IsA("BasePart") then
			if part.Name ~= "HumanoidRootPart" then
				part.RootPriority = 2
			else
				part.RootPriority = 3
			end
		end
	end
	
	for _, part in pairs(controllCharacter:GetChildren()) do
		if part:IsA("BasePart") then
			if part.Name ~= "HumanoidRootPart" then
				local weld = Instance.new("Weld", controllCharacter:FindFirstChild("controlWelds"))
				weld.Part0 = part
				weld.Part1 = modelControll:FindFirstChild(part.Name)
			end
		end
	end
	
	for i=1, 5 do
		modelControll.HumanoidRootPart.CFrame = toTeleportCF
		task.wait()
	end
	
	controllCharacter.HumanoidRootPart.Anchored = false
end

function FusionModule:RemoveControll(modelControll: Model, controllCharacter: Model)
	if modelControll:GetAttribute("Host") == controllCharacter then
		controllCharacter:FindFirstChild("controlWelds"):ClearAllChildren()
		
		for _, part in pairs(controllCharacter:GetChildren()) do
			if part:IsA("BasePart") then
				if part.Name ~= "HumanoidRootPart" then
					part.RootPriority = 0
				else
					part.RootPriority = 1
				end
			end
		end

		modelControll.Humanoid.PlantformStand = false
	end
end

function FusionModule:Fuse(character1: Model, character2: Model)
	if character1:HasTag("Fused") or character2:HasTag("Fused")  then
		return
	end
	
	local plr1 = Players:GetPlayerFromCharacter(character1)
	local plr2 = Players:GetPlayerFromCharacter(character2)
	
	local firstName = character1.Name
	local secondName = character2.Name
	
	if plr1 then
		firstName = plr1.DisplayName
	end
	
	if plr2 then
		secondName = plr2.DisplayName
	end

	local firstPart = string.sub(firstName, 1, string.len(firstName) / 2)
	local secondPart = string.sub(secondName, string.len(secondName) / 2, string.len(secondName))
	
	local newFusionName = firstPart .. secondPart
	
	if character1 and character2 then
		character1:AddTag("Fusioning")
		character2:AddTag("Fusioning")
		
		FusionModule.AlreadyFusioning[character1] = true
		
		glowModel(character1)
		glowModel(character2)
		
		character1.HumanoidRootPart.Anchored = true
		character2.HumanoidRootPart.Anchored = true
		
		local positionBetwen = (character1.HumanoidRootPart.Position + character2.HumanoidRootPart.Position) / 2
		local cframe = CFrame.new(positionBetwen)
		
		tweenToPos(character1, cframe)
		tweenToPos(character2, cframe)
		
		task.wait(0.3)
		
		hideModel(character1)
		hideModel(character2)
		
		local templateClone = script.Template:Clone()
		templateClone.Name = newFusionName
		templateClone.HumanoidRootPart.Anchored = true
		templateClone.Humanoid.PlatformStand = true
		templateClone:PivotTo(character1.HumanoidRootPart.CFrame)
		tweenToPos(templateClone, character1.HumanoidRootPart.CFrame)
		
		templateClone.Parent = workspace.Characters
		
		templateClone:SetAttribute("Host", character1.Name)
		
		character1:FindFirstChildWhichIsA("Highlight"):Destroy()
		character2:FindFirstChildWhichIsA("Highlight"):Destroy()
		
		local highlight = Instance.new("Highlight")
		highlight.FillTransparency = 0
		highlight.FillColor = Color3.fromRGB(255, 255, 255)
		highlight.OutlineTransparency = 1
		highlight.Adornee = templateClone
		highlight.Parent = templateClone
		
		character1.Parent = workspace.Spectators
		character2.Parent = workspace.Spectators
		
		FusionModule:CreateAccessorysFusion(character1, character2, templateClone)
		templateClone.HumanoidRootPart.Anchored = false
		
		unglowModel(templateClone)
		FusionModule:GiveControl(templateClone, character1)
		
		character1:RemoveTag("Fusioning")
		character2:RemoveTag("Fusioning")
		
		templateClone:AddTag("Fusioning")
		
		if plr2 ~= nil then
			MainCameraEvent:FireClient(plr2, "SetToAnother", {
				Character = templateClone
			})
		end
		
		task.delay(2, function()
			FusionModule:UnFuse(character1, character2, templateClone)
			
			if plr2 ~= nil then
				MainCameraEvent:FireClient(plr2, "SetToDefault")
			end
		end)
	end
end

function FusionModule:UnFuse(character1: Model, character2: Model, fusionModel: Model)
	character1:AddTag("Fusioning")
	character2:AddTag("Fusioning")
	
	character1.HumanoidRootPart.Anchored = true
	character2.HumanoidRootPart.Anchored = true
	
	local fuseHrp: BasePart = fusionModel.HumanoidRootPart
	
	task.wait(0.5)
	
	glowModel(fusionModel)
	glowModel(character1)
	glowModel(character2)
	
	character1:PivotTo(fuseHrp.CFrame * CFrame.new(0, 1.5, 0))
	character2:PivotTo(character1.HumanoidRootPart.CFrame)
	
	task.wait(0.2)
	
	showModel(character1)
	showModel(character2)
	
	fusionModel:Destroy()
	
	task.wait(0.5)
	
	unglowModel(character1)
	unglowModel(character2)
	
	character1.HumanoidRootPart.Anchored = false
	character2.HumanoidRootPart.Anchored = false
	
	character1.Parent = workspace.Characters
	character2.Parent = workspace.Characters
	
	task.delay(2, function()
		character1:RemoveTag("Fusioning")
		character2:RemoveTag("Fusioning")
	end)
end

return FusionModule

If u know how to, pleases answer this topic! I really indeed in this thing

Store the other characters in a array and display the top one only, you can move the rest + the original with the highest index or just hide the rest and teleport character you are removing from the array.

1 Like

A little offtopic but would be cool if usernames would also merge in character (assuming you disconnect character from player for a split second to rename it)

Etc: Bob321+Joe456 = Bob456

local name1,name2:string = "Bob321","Joe456"
local numArray = table.create(#name1)::{string}

for i in string.gmatch(name2,"%d") do
	table.insert(numArray,i)
end
local i:number = 0

print(string.gsub(name1,"%d",function(t):string
	i+=1
	return numArray[i] or t
end))
1 Like

nash from dream game REAL !!

#mysoulhasbeenfrozenandimustdreaminthisgame

1 Like

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