local C=game:GetService("\082\101\112\108\105\099\097\116\101\100\083\116\111\114\097\103\101")local g=C:WaitForChild("\077\111\100\117\108\101\115")local q=require(g.src.utils.Logger)local h=game.Workspace:WaitForChild("\080\108\097\099\101")local x={}x.__index=x function x.new(C,g)local t=C if type(C)=="\115\116\114\105\110\103"then local g=h.Lobby.Portals:FindFirstChild(C)if not g then q:e("\080\111\114\116\097\108"..(C.." \110\111\116 \102\111\117\110\100"))end end return setmetatable({teleportTo=C,portalTo=t;portalFrom=g},x)end function x.isHuman(g,C)if C.Parent==nil then return false end local q=C.Parent:FindFirstChild("\072\117\109\097\110\111\105\100\082\111\111\116\080\097\114\116")if q then return true end return false end function x.onTouch(C)return function(g)if C:isHuman(g)and C.portalFrom.Enabled.Value then local q=g.Parent.HumanoidRootPart q.CFrame=CFrame.new(C.portalTo.CFrame.p-Vector3.new(0,-5,5))end end end return x
local ReplicatedStorage = game:GetService('ReplicatedStorage')
local Modules = ReplicatedStorage:WaitForChild('Modules')
local logger = require(Modules.src.utils.Logger)

local Place = game.Workspace:WaitForChild('Place')

local Portal = {}

Portal.__index = Portal

function Portal.new(teleportTo, portalFrom)
	local portalTo = teleportTo
	if type(teleportTo) == 'string' then
		local portalTo = Place.Lobby.Portals:FindFirstChild(teleportTo)
		if not portalTo then
			logger:e('Portal' .. teleportTo .. ' not found')
		end
	end

	return setmetatable(
		{
			teleportTo = teleportTo,
			portalTo = portalTo,
			portalFrom = portalFrom,
		},
		Portal
	)
end

function Portal:isHuman(hit)
	if hit.Parent == nil then
		return false
	end
	local humanoid = hit.Parent:FindFirstChild('HumanoidRootPart')
	if humanoid then
		return true
	end

	return false
end

function Portal:onTouch()
	return function(hit)
		if self:isHuman(hit) and self.portalFrom.Enabled.Value then
			local humanoid = hit.Parent.HumanoidRootPart
			-- self.portalFrom.Enabled.Value = false
			-- humanoid.CFrame = self.portalTo.CFrame
			humanoid.CFrame = CFrame.new(self.portalTo.CFrame.p - Vector3.new(0, -5, 5))
			-- wait(5)
			-- self.portalFrom.Enabled.Value = true
		end
	end
end

return Portal