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=require(g.src.ModelManager)local x=game.Workspace:WaitForChild("\080\108\097\099\101")local t=x.Spawns:GetChildren()local e={}local P=Vector3.new(0,5,0)function freezeCharacter(C,g)for C,q in pairs(C:GetChildren())do if q:IsA("\066\097\115\101\080\097\114\116")then q.Anchored=g end end end function e.fadePlayerTo(t,C,g,h,x)for g=g,h,x do if C.Character then for C,q in ipairs(C.Character:GetDescendants())do if q:IsA("\066\097\115\101\080\097\114\116")and q.Name~="\072\117\109\097\110\111\105\100\082\111\111\116\080\097\114\116"or q:IsA("\068\101\099\097\108")then q.Transparency=g end end wait(.1)else q:d("\078\111 \067\104\097\114\097\099\116\101\114 \102\111\117\110\100 \102\111\114 \112\108\097\121\101\114\058"..C.Name)end end end function e.transportPlayers(x,C,g)for C,x in pairs(C)do if x.Character then local C=x.Character.HumanoidRootPart if C then x:RequestStreamAroundAsync(g.Position)C.CFrame=h:onlyDirection(g.CFrame)+P end else q:d("\078\111 \067\104\097\114\097\099\116\101\114 \102\111\117\110\100 \102\111\114 \112\108\097\121\101\114\058"..x.Name)end end end function e.transportByKillingPlayers(g,C)for C,g in pairs(C)do if g.Character then g.Character.Humanoid.Health=0 else q:d("\078\111 \067\104\097\114\097\099\116\101\114 \102\111\117\110\100 \102\111\114 \112\108\097\121\101\114\058"..g.Name)end end end function e.teleportTo(x,C,g)if C.Character then local q=C.Character.HumanoidRootPart if q then C:RequestStreamAroundAsync(g.Position)q.CFrame=h:onlyDirection(g.CFrame)+P end else q:d("\078\111 \067\104\097\114\097\099\116\101\114 \102\111\117\110\100 \102\111\114 \112\108\097\121\101\114\058"..C.Name)end end function e.placePlayerToHomeSpawn(g,C)local q=t[math.random(1,#t)]C.RespawnLocation=q e:teleportTo(C,q)end function e.placePlayersToHomeSpawn(g,C)for C,g in pairs(C)do e:placePlayerToHomeSpawn(g)end end return e
local ReplicatedStorage = game:GetService('ReplicatedStorage')
local Modules = ReplicatedStorage:WaitForChild('Modules')
local logger = require(Modules.src.utils.Logger)
local ModelManager = require(Modules.src.ModelManager)

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

local Transporter = {}

local offset = Vector3.new(0, 5, 0)

function freezeCharacter(character, isAnchored)
	for _, part in pairs(character:GetChildren()) do
		if part:IsA('BasePart') then
			part.Anchored = isAnchored
		end
	end
end

function Transporter:fadePlayerTo(player, a, b, c)
	for transparency = a, b, c do
		-- go from a to b, counting by c
		if player.Character then
			for _, v in ipairs(player.Character:GetDescendants()) do
				if v:IsA('BasePart') and v.Name ~= 'HumanoidRootPart' or v:IsA('Decal') then
					v.Transparency = transparency
				end
			end
			wait(0.1)
		else
			logger:d('No Character found for player:' .. player.Name)
		end
	end
end

function Transporter:transportPlayers(players, target)
	for i, player in pairs(players) do
		if player.Character then
			-- Transporter:fadePlayerTo(player, 0, 1, 0.1) --fade out,

			local rootPart = player.Character.HumanoidRootPart
			if rootPart then
				player:RequestStreamAroundAsync(target.Position)
				rootPart.CFrame = ModelManager:onlyDirection(target.CFrame) + offset
			end
			-- Transporter:fadePlayerTo(player, 1, 0, -0.1) --fade back in
		else
			logger:d('No Character found for player:' .. player.Name)
		end
	end
end

function Transporter:transportByKillingPlayers(players)
	for i, player in pairs(players) do
		if player.Character then
			player.Character.Humanoid.Health = 0
		else
			logger:d('No Character found for player:' .. player.Name)
		end
	end
end

function Transporter:teleportTo(player, target)
	-- fadePlayerTo(player, 0, 1, 0.1) --fade out,
	if player.Character then
		local rootPart = player.Character.HumanoidRootPart
		if rootPart then
			player:RequestStreamAroundAsync(target.Position)

			rootPart.CFrame = ModelManager:onlyDirection(target.CFrame) + offset
		end
	else
		logger:d('No Character found for player:' .. player.Name)
	end
	-- fadePlayerTo(player, 1, 0, -0.1) --fade back in
end

function Transporter:placePlayerToHomeSpawn(player)
	local RandomSpawn = Spawns[math.random(1, #Spawns)]
	player.RespawnLocation = RandomSpawn
	Transporter:teleportTo(player, RandomSpawn)
end

function Transporter:placePlayersToHomeSpawn(players)
	for i, player in pairs(players) do
		Transporter:placePlayerToHomeSpawn(player)
	end
end

return Transporter