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)