Morph/Teleport Issue

Hi, I made a script that teleports you to a random spot in a arena after you enter a portal. I tried experimenting with a morph so that it also morphs you once you enter the portal, but it’s not working. Please try to find what is wrong with my code and help me improve. Here’s the code: ```

local destination = game.Workspace.Portal:FindFirstChild("Gavin2") 
local destination2 = game.Workspace.Portal:FindFirstChild("Gavin3")
local destination3 = game.Workspace.Portal:FindFirstChild("Gavin4")
local destination4 = game.Workspace.Portal:FindFirstChild("Gavin5")
local destination5 = game.Workspace.Portal:FindFirstChild("Gavin6")
local spawns = {destination2, destination3, destination4, destination5}
part.Touched:Connect(function(hit)
	local character = hit.Parent
	local humanoidRootPart = character:FindFirstChild("HumanoidRootPart")
if humanoidRootPart and destination and destination2 and destination3 and destination4 and destination5 then
		local random = math.random(1,#spawns)
		if random == 1 then
			humanoidRootPart.CFrame = destination.CFrame
		else
			humanoidRootPart.CFrame = spawns[random].CFrame
		end
	end
end)
local characterName = game.Workspace.Model.Spongebob.Morph
local character = part.Parent:WaitForChild(characterName)
local debounce = true
part.Touched:Connect(function(obj)
	local plr = game.Players:GetPlayerFromCharacter(obj.Parent)
	if plr and debounce == true then
		debounce = false
local charClone = character:Clone()
		charClone.Name = plr.Name
		plr.Character = charClone
local rootPart = charClone:FindFirstChild("HumanoidRootPart") or charClone:FindFirstChild("Torso")
		local plrRoot = obj.Parent:FindFirstChild("HumanoidRootPart") or obj.Parent:FindFirstChild("Torso")
if rootPart and plrRoot then
			rootPart.CFrame = plrRoot.CFrame
		end
charClone.Parent = workspace
		wait(.5)
		debounce = true
	end
end)

There are a few issues with this script but the most important one is using two of the same event in one script. You shouldn’t be doing this because one event is enough. Also, things seem to be just randomly placed like the variables. Because I was already on Studio working on some things I edited and cleaned your code. Try this and see if it works:

local Spawns  = {}

local characterName = game.Workspace.Model.Spongebob.Morph
local character = part.Parent:WaitForChild(characterName)

local Debounce = false
local DebounceTime = .5

for Index, Destination in workspace.Portal:GetChildren() do
	local Name = Destination.Name
	
	local Part1 = Name:sub(1, 5)
	local Part3 = tonumber(Name:sub(6, 6))
	
	if Part1 == "Gavin" and Part3 and Part3 > 1 then
		table.insert(Spawns, Destination)
	end
end

local function MorphAndTP(Player:Player, NewCharacter:Model, TpLocation:CFrame)
	if not Player or not NewCharacter or not TpLocation then return end

	local Char = Player.Character
	if not Char then return end 

	local Humanoid = Char:FindFirstChildOfClass("Humanoid")
	if not Humanoid or Humanoid:GetState() == Enum.HumanoidStateType.Dead then return end

	Humanoid.RootPart.Anchored = true

	local NewChar = NewCharacter:Clone()
	NewChar.Name = Char.Name
	Player.Character = NewChar

	for _, X in game:GetService("StarterPlayer").StarterCharacterScripts:GetChildren() do
		if X:IsA("Script") then
			X:Clone().Parent = NewChar
		end
	end

	NewChar.Parent = workspace

	NewChar:PivotTo(TpLocation)
	Char:Destroy()
end

part.Touched:Connect(function(hit)
	if Debounce then return end
	
	local Player = game:GetService("Players"):GetPlayerFromCharacter(hit.Parent)
	if not Player then return end
	
	Debounce = true
	
	MorphAndTP(Player, character, Spawns[math.random(#Spawns)].CFrame)
	
	task.wait(DebounceTime)
	Debounce = false
end)

Thank you, it still doesn’t work right now but I’m trying my best to fix it