-- Set up portals

for _,portal in pairs(workspace.Portals:GetChildren()) do
	local label = script.PortalLabel:Clone()
	label.RankLabel.Text = portal.RequiredRank.Value
	label.Parent = portal.Portal
	portal.Portal.Touched:Connect(function(part)
		local player = players:GetPlayerFromCharacter(part.Parent)
		if player and player.Stats.Rank.Value >= portal.RequiredRank.Value and not portal:FindFirstChild(player.Name .. "Cooldown") then
			replicatedStorage.ClientRemotes.TeleportToArea:FireClient(player, portal.AreaToTeleportTo.Value.Name)
			player.Stats.CurrentArea.Value = portal.AreaToTeleportTo.Value
			player.RespawnLocation = portal.AreaToTeleportTo.Value.Spawn
			local tag = Instance.new("Model")
			tag.Name = player.Name .. "Cooldown"
			tag.Parent = portal
			game:GetService("Debris"):AddItem(tag, 3)
		end
	end)
end
