i was try to make this swap switch a new Character without destroying the old one when a player touches a new character (illusion) it’s should destroy the new character and character return to their old character
local function Clone(Player, Character)
if game.Workspace:FindFirstChild(Character.Name) then
Character.Archivable = true
local NewCharacter = Character:Clone()
local PlayerRoot = Character:FindFirstChild("HumanoidRootPart")
if NewCharacter:FindFirstChild("HumanoidRootPart") then
NewCharacter.PrimaryPart = NewCharacter.HumanoidRootPart
elseif NewCharacter:FindFirstChild("Torso") then
NewCharacter.PrimaryPart = NewCharacter.Torso
end
if PlayerRoot and NewCharacter.PrimaryPart then
local SpawnOffset = Vector3.new(5,0,5)
NewCharacter:SetPrimaryPartCFrame(PlayerRoot.CFrame + SpawnOffset)
end
Character.Archivable = false
NewCharacter.Name = "Mirage_" .. Character.Name .. "_Clone"
NewCharacter.Parent = game.Workspace
for _, v in ipairs(NewCharacter:GetDescendants()) do
if v:IsA("Accessory") then
if v.Name == "hand stick" or v.Name == "Background" or v.Name == "mirage effect" then
v:Destroy()
elseif v.Name == "flute" then
if v:FindFirstChild("Handle") and v.Handle:FindFirstChild("FLUTE FOX") then
v.Handle["FLUTE FOX"].Transparency = 0
end
end
end
end
for _, Part in ipairs(NewCharacter:GetDescendants()) do
if Part:IsA("BasePart") then
Part:SetNetworkOwner(Player)
end
end
local bSwap = false
Player.PlayerGui.MirageGui.Mirage.Visible = true
Player.PlayerGui.MirageGui.Mirage.MouseButton1Click:Connect(function()
if not bSwap then
bSwap = true
--Swap to New Player and do not make it reset the old player so it can swap back (bSwap = false) to the old player
elseif bSwap then
end
end)
end
end
if you figure this issue out that would be very helpful!
Thank you!